Results 1 to 8 of 8

Thread: store QlistWidget

  1. #1
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default store QlistWidget

    I have an app when connect internet, it will retrieve data by web service to display on QlistWidget.
    i want that when exit app then app will store QlistWidget to when start app, if it disconnect internet then it will retrieve data previously stored (same bookmark)

    i tried by store into QList<QListWidgetItem*> but it displays empty (sorry my english)

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: store QlistWidget

    Can't you iterate over the items and store it in a custom text file and when you start up, simple read that file and restore the list widget. Or show us some code you have so far.

  3. The following user says thank you to Lykurg for this useful post:

    jindoniit (15th July 2011)

  4. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: store QlistWidget

    It is not very clear what you want, this what I understand

    1. If you want to store data when app exits, and restore data when app starts, then you can QSettings to save and restore data (Note that you can only save data in QListWidget / QListWidgetItem, you cannot save QListWidget / QListWidgetItem itself)

    2. If you want to store data when internet is disconnected, and restore data when internet restores, then you can use a container to store QListWidgetItem, using QList<QListWidgetItem*> (this would work if item is not already added to table)
    Last edited by Santosh Reddy; 15th July 2011 at 10:32.

  5. The following user says thank you to Santosh Reddy for this useful post:

    jindoniit (15th July 2011)

  6. #4
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default Re: store QlistWidget

    this is my example

    Qt Code:
    1. for (int i =0; i<12;i++)
    2. {
    3.  
    4. QListWidgetItem *item = new QListWidgetItem(this->ui->listWidget);
    5.  
    6. QPixmap pix=icon.pixmap(QSize(400,400),QIcon::Selected,QIcon::On);
    7. item->setSizeHint(QSize(200,60));
    8. itemwid = new itemWidget(this);
    9. itemwid->ui->lblImage->setPixmap(pix.scaled(pix.size(),Qt::KeepAspectRatio,Qt::SmoothTransformation));
    10. itemwid->ui->lbl1->setText(tr("row number %1").arg(i));
    11. itemwid->ui->lbl2->setText(tr("row number %1").arg(i+1));
    12. this->ui->listWidget->setItemWidget(item,itemwid);
    13.  
    14. // store data into Qlist<QlistWidgetItem*>
    15. itemTemp->append(item);
    16.  
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    besides, if i use xml to store item ,then is it feasible?
    Attached Files Attached Files

  7. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: store QlistWidget

    I remember helping on the same example project, are you the same user

    Ok, here you have bunch of problems

    1. when you clear the list widget, all the items and itemwidgets are deleted, so there is no use of storing the pointers to items in a list, it will crash your program.
    2. what you need to store is data, using with you can recreate the item and item widgets
    3. your program crashes, if button is clicked before all images load (debug this, may be later)
    3. one coding error as below

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. ...
    4. // for (int i=0;i<<itemTemp->length();i++) //note the '<<' operator
    5. for (int i=0;i<itemTemp->length();i++)
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    again I took some time to fix the problems and change the class implementation a bit, check this out.
    example_changed.zip
    Last edited by Santosh Reddy; 15th July 2011 at 10:42.

  8. The following user says thank you to Santosh Reddy for this useful post:

    jindoniit (15th July 2011)

  9. #6
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default Re: store QlistWidget

    thanks Santosh Reddy
    yes, you've helped me.
    I have identified a method of solving this the problem. although my real subject is slightly more complicated than this example but I'll solve it more easily.

    if i want store data into xml , to when app starts (disconnect internet) then it will retrieve data previously stored. is it feasible?
    thank you so much
    Last edited by jindoniit; 15th July 2011 at 10:42.

  10. #7
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: store QlistWidget

    it is possible, it depends what data you want to store, if you want to store simple QString, QUrl etc then xml is ok, but if you want to store QIcon, QPixmap, then you need store the them in in separate image files, and store the image file names in xml.

  11. The following user says thank you to Santosh Reddy for this useful post:

    jindoniit (15th July 2011)

  12. #8
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default Re: store QlistWidget

    oh , i understood, i will try to store data into xml.

Similar Threads

  1. Mac App Store
    By serkol in forum Installation and Deployment
    Replies: 20
    Last Post: 1st December 2011, 13:29
  2. Replies: 2
    Last Post: 1st April 2011, 10:32
  3. store number in QByteArray
    By sattu in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2011, 14:27
  4. Query - how to store ?
    By damodharan in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2010, 13:59
  5. Turn off backing store
    By Rayven in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2007, 19:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.