Results 1 to 5 of 5

Thread: listWidget select item, return index?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2012
    Posts
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default listWidget select item, return index?

    Need right way to recieve item index when changed to another item

    need use currentRowChanged ? How?

    i have

    Qt Code:
    1. void View::unzipdone(QString namepath)
    2. {
    3. QDir dir(namepath);
    4. uint i = 1;
    5. QStringList filters;
    6.  
    7. filters << "*.jpg" << "*.png" << "*.bmp";
    8. dir.setNameFilters(filters);
    9.  
    10. foreach (QFileInfo mitm, dir.entryInfoList())
    11. {
    12. ui->listWidget->addItem("picture "+QString::number(i));
    13. i++;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by noborder; 7th January 2013 at 12:19.

  2. #2
    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: listWidget select item, return index?

    Could you reword the question?

    From where you want to send item (emit signal) view/model/item?
    To where you want to receive item index (slotl) view/model/item?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Dec 2012
    Posts
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: listWidget select item, return index?

    when activate item in listWidget (via mouse click, or keyboard) emit signal with item index.

    i do

    Qt Code:
    1. void View::unzipdone(QString namepath)
    2. {
    3. QDir dir(namepath);
    4. uint i = 1;
    5. QStringList filters;
    6.  
    7. filters << "*.jpg" << "*.png" << "*.bmp";
    8. dir.setNameFilters(filters);
    9.  
    10. foreach (QFileInfo mitm, dir.entryInfoList())
    11. {
    12. ui->listWidget->addItem("picture "+QString::number(i));
    13. i++;
    14. }
    15. connect(ui->listWidget, SIGNAL(currentRowChanged(int)), &m_imageviewer, SLOT(picindex(int))); //error
    16. }
    To copy to clipboard, switch view to plain text mode 

    recieve error : no matching function for call to 'ComicView::connect(QListWidget*&, const char*, ImageViewer*, const char*)'
    ????

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: listWidget select item, return index?

    try:
    Qt Code:
    1. QObject::connect(ui->listWidget, SIGNAL(currentRowChanged(int)), &m_imageviewer, SLOT(picindex(int)));
    To copy to clipboard, switch view to plain text mode 
    i'm not sure that will help, you have some modifications (at least ComicView from error and View:: in code) after you got the error you told us, so if that won't help post the updated code and error message.

    Also are you sure that you want to connect when unzipdone (instead of for example in the ComicView constructor)?
    And make sure that m_imageviewer stays alive as long as you need it to receive the changes to selection.

  5. #5
    Join Date
    Dec 2012
    Posts
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: listWidget select item, return index?

    Found error

    m_imageviewer isn`t inherited from QObject

    thx

Similar Threads

  1. Sort Qlist and return index
    By enricong in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2012, 14:19
  2. ListWidget -> custom Item -> height
    By Archa4 in forum Newbie
    Replies: 5
    Last Post: 4th February 2011, 11:36
  3. ListWidget item's height
    By BalaQT in forum Qt Programming
    Replies: 1
    Last Post: 12th July 2010, 13:51
  4. ListWidget positions item
    By talex in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2008, 15:16
  5. ListWidget select style
    By CopyrightPhilly in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2007, 08:45

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.