MTextListBoxModel implementation problems.

Login to reply to this topic.
Mon, 2005-03-28 11:26
Joined: 2005-03-28
Forum posts: 11
Hi. I have problems impelementing MTextListBoxModel model in my application.

The implementation works on the simulator, but not on the device.
Here is a sample implementation:

_LIT(T,"TEST");

int CListBoxModel::NumberOfItems() const
{
   return 6;
}

const MDesCArray* CListBoxModel::MatchableTextArray() const
{
   return 0;
}

TPtrC CListBoxModel::ItemText(TInt aItemIndex) const
{
   return TPtrC(T);
}

This works perfectly on the simulator, but crashes on the device.
Any suggestions?

Mon, 2005-03-28 12:18
Joined: 2004-05-24
Forum posts: 982
Re: MTextListBoxModel implementation problems.
What's this "_LIT(T,"TEST"); "?  A global variable?

And where exactly crashes on the device?

pirosl

Tue, 2005-03-29 08:55
Joined: 2005-03-28
Forum posts: 11
MTextListBoxModel implementation problems.
Yes T is a global variable. it crashes in

TPtrC CListBoxModel::ItemText(TInt aItemIndex) const
{
 return TPtrC(T);
}

I've tried different kidn of things
HBuf, TBuf, allocating on the heap, etc.
the result is the same, so i post the simplest form.

This crashes on several devices, that I have tested.
Tue, 2005-03-29 09:29
Joined: 2004-05-24
Forum posts: 982
MTextListBoxModel implementation problems.
First remove T. Then try this

TPtrC CListBoxModel::ItemText(TInt aItemIndex) const
{
_LIT(KText,"My List Model");
TBufC<16> buf1(KText);
return TPtrC(buf1);
}

pirosl

Tue, 2005-03-29 09:35
Joined: 2005-03-28
Forum posts: 11
MTextListBoxModel implementation problems.
TPtrC CListBoxModel::ItemText(TInt aItemIndex) const
{
   _LIT(KText,"My List Model");
   TBufC<16> buf1(KText);
   return TPtrC(KText);
}

This Returns My List Model in the ListBox on the simulator

TPtrC CListBoxModel::ItemText(TInt aItemIndex) const
{
   _LIT(KText,"My List Model");
   TBufC<16> buf1(KText);
   return TPtrC(buf1);
}

This returns nonsense in the listitems of the listbox on the simulator
as if it displays uninitialized data
Tue, 2005-03-29 09:52
Joined: 2004-05-24
Forum posts: 982
MTextListBoxModel implementation problems.
Yes sorry...you're rigth Smiley. In my example data from buf1 is accessible throught returned TPtrC but when you use that ptrC, buf1 doesn't exist any more (since it is on stack).

So simply do

TPtrC CListBoxModel::ItemText(TInt aItemIndex) const
{
_LIT(KText,"My List Model");
return TPtrC(KText);
}

This should work.

pirosl

Tue, 2005-03-29 10:05
Joined: 2005-03-28
Forum posts: 11
MTextListBoxModel implementation problems.
Unfortunately i doesn't work, too. Smiley

That's why I posted this.

If you wish, i can post here the whole infrastructure setup of the listbox, etc..
If you have a phone to try it. I have nokia 6630 and i cannot setup gdb on it, because they have no com server installed on it.

I cannot explain why is this?  Very, very strange Smiley
Tue, 2005-03-29 10:47
Joined: 2004-05-24
Forum posts: 982
MTextListBoxModel implementation problems.
Quote from: kingofthebongo
Unfortunately i doesn't work, too. Smiley

That's why I posted this.

If you wish, i can post here the whole infrastructure setup of the listbox, etc..
If you have a phone to try it. I have nokia 6630 and i cannot setup gdb on it, because they have no com server installed on it.

I cannot explain why is this?  Very, very strange Smiley

I have a nokia 3660. Can you send me the package by email?

pirosl

Tue, 2005-03-29 10:55
Joined: 2005-03-28
Forum posts: 11
MTextListBoxModel implementation problems.
of course i can. where can i send it ?
Tue, 2005-03-29 11:08
Joined: 2004-05-24
Forum posts: 982
MTextListBoxModel implementation problems.
check my contact details in userllist

pirosl

Tue, 2005-03-29 13:24
Joined: 2005-03-28
Forum posts: 11
MTextListBoxModel implementation problems.
i've sent an email
Wed, 2005-03-30 15:06
Joined: 2005-03-28
Forum posts: 11
MTextListBoxModel implementation problems.
Thank you for your cooperation.

Unfortunately the problem is not yet resolved Smiley
The sample imeplementation works on 3660. Also I've managed to test it on Nokia 7650. It works there two.

On Nokia 6630 it crashes, it also crashes on Nokia 6670

I've managed to locate the problem. The problem is in the Drawer
not in the ListBoxModel.

I will post some code later for the people in this forum.
Thu, 2005-03-31 11:36
Joined: 2005-03-28
Forum posts: 11
MTextListBoxModel implementation problems.
So far, the guys i have discovered the problem, so I'm posting for comments
if anyone is interested

Typically when one subclasses a listbox a drawer is used too. Smiley

  drawer=new (ELeave) CTextListItemDrawer(model,CEikonEnv::Static()->NormalFont());
   CleanupStack::PushL(drawer);
   drawer->ConstructL(CEikonEnv::Static()->NormalFont());
   CleanupStack::Pop();

so, the bug in the implementation of CTextListItemDrawer
in the function DoDrawItemText this is where s60 nokia 6630, 6670 and other models crash (the simulator for 7.0s crashes too). This does not crash on the older models

but if you write:
  drawer=new (ELeave) CTextListItemDrawer(model,CEikonEnv::Static()->NormalFont());

then everything is ok on the new models.

Generally the problem is in the intefaces and most of all poor, poor documentation and lack of good examples.


for example only series 60 1.2 has CTextListItemDrawer if you search in the help file
Wed, 2005-04-27 15:21
Joined: 2005-02-21
Forum posts: 47
MTextListBoxModel implementation problems.
How do you use your own model with listbox?
I ask because I fail to implement my own listbox model and associate it with the listbox.

What I do is this: I derive my own listbox class form CAknDoubleStyleListBox (that's the style I want) and override the ContructL. At the ConstructL I create my own model and give it to CEikListBox::ConstructL(model, drawer...). As I result I see that the listbox internal structure has a whole different address for iModel and of course getting the model with Model() does give a whole a different object. And to mention - none of my overridden model function are called.
Any help appreciated.

tnx in advance
 Ahti.
Wed, 2005-04-27 19:27
Joined: 2005-02-21
Forum posts: 47
MTextListBoxModel implementation problems.
To answer my question above ... one does not have to reimplement model. As long as you can provide your own MDesCArray-inherited data to the model.

That's the advice to the original poster as well - instead of reimplementing model (which I personally failed big times), add MDesCArray to your data class and provide two simple methods: MdcaCount and MdcaPoint.
Easy as abc.

Ahti.
  • Login to reply to this topic.