PDA

View Full Version : QListView is not showing contnet



hrudhay
20th August 2008, 13:31
i created QListView to show my model content like this.


Play::Play( QWidget *parent, Qt::WFlags f )
: QWidget( parent, f )
{
QContentSet contentset;
contentset.addCriteria(QContentFilter::MimeType, "audio/*", QContentFilter::Or);
QContentSetModel model( &contentset );
listView= new QListView(this);
listView->setModel( &model );
vboxLayout = new QVBoxLayout(this);
vboxLayout->addWidget(listView);
this->setLayout(vboxLayout);
this->show();
}

i added some other components in the vboxLayout.

but the list is not showing any content, even model(QContentSetModel) had content.

jpn
20th August 2008, 14:20
The model goes out of scope. Allocate it with C++ operator new.

hrudhay
20th August 2008, 14:39
in Qt Assistant manual he provided example:



QContentSet contentset( QContentFilter::Directory, "/Documents" );
QContentSetModel model( &contentset );

QListView listview( this );
listview->setModel( &model );

i did in the same way.
and i tried with new operation also.
it's not working.


Hrudhay

jpn
20th August 2008, 15:01
The reference documentation expects basic C++ knowledge from its reader. Example snippets are kept as simple as possible for the sake of readability. Anyway, you're passing pointers to stack variables. What do you expect to happen when they go out of scope? They are both (the content set and the model) QObjects which cannot be copied.

So, exactly the same fault applies to the content set. Once the content set goes out of scope, the model has nothing to show.

hrudhay
21st August 2008, 07:31
Thanks..

now it is working.