Results 1 to 5 of 5

Thread: Help! How to implement CHECK & RETURN in signal/slots

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Red face Help! How to implement CHECK & RETURN in signal/slots

    I am using Qt to develop a really big software, but I got some trobule in resolving UI-Frozen-Issue in Qt framework.

    For example, I have a widget named "Picture wall", which lists all the pictures in one directory, with each picture represented by a icon and a label.

    After user click the icon or label, a signal will be issued and the slot on_picture_wall_item_clicked will be launched, then the picture clicked will be loaded to canvas.

    If user click the items in picture wall one by one very fast, then the UI will be frozen, and the pictures clicked by user will be loaded one by one.

    Of course I want the slot to CHECK whether this slot is busy (loading some other picture), if it's busy, the slot must return immediately.

    My problems is that the "CHECK & RETURN" doesn't work at all. See my codes below:

    Qt Code:
    1. void MusePictureWallWidget::on_picture_wall_item_clicked(const QString& fileName)
    2. {
    3. if(!m_mutex.tryLock())
    4. return;
    5.  
    6. if(m_busy)
    7. return;
    8.  
    9. m_busy=true;
    10.  
    11. this->setCursor(Qt::WaitCursor);
    12.  
    13. disconnect(ui.listViewPhotoWall, SIGNAL(pictureDoubleChecked(const QString &)),this, SLOT(on_picture_wall_item_clicked(const QString&)));
    14.  
    15. this->setEnabled(false);
    16. ui.listViewPhotoWall->setEnabled(false);
    17. this->repaint();
    18.  
    19. QDialog dlg;
    20. dlg.setModal(true);
    21. dlg.show();
    22.  
    23. loadPicture(fileName);
    24.  
    25. dlg.hide();
    26.  
    27. m_busy=false;
    28.  
    29. ui.listViewPhotoWall->setEnabled(true);
    30. this->setEnabled(true);
    31.  
    32. connect(ui.listViewPhotoWall, SIGNAL(pictureDoubleChecked(const QString &)),this, SLOT(on_picture_wall_item_clicked(const QString&)), Qt::DirectConnection);
    33.  
    34. this->unsetCursor();
    35.  
    36. m_mutex.unlock();
    37. }
    To copy to clipboard, switch view to plain text mode 

    I tried 5 ways to implement the "CHECK & RETURN" in my slots.

    1, QMutex, I used a mutex to lock and lock the slot, if it's occupied, the slot call should return at once.
    2, An flag m_busy, the slot should then check the flag, if m_busy is true, it should return at once.
    3, When a slot is launched, I disconnected this current signal/slot and reconnect them after the loading is done.
    4, I raise a Modal Dialog when the slot is launched, so that the picture wall will not be clickable until the loading is done and the dialog is hiden.
    5, I disable the picture wall after one slot is launched, and then enable it after loading is done.

    BUT......all these did not work!!! What's wrong with my codes? How can I fix this problem? Help! Help!
    Last edited by apollocheun; 23rd July 2010 at 08:06.

Similar Threads

  1. QWebpage always return false for signal loadfinished
    By QtVenkat in forum Qt Programming
    Replies: 0
    Last Post: 4th June 2010, 20:50
  2. how to check if a signal in emited or not??
    By sudhansu in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2009, 08:51
  3. How to Implement signal and slots for QAccessibleWidget
    By Rakesh_Kumar in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2009, 06:57
  4. check box and signal
    By mickey in forum Newbie
    Replies: 7
    Last Post: 10th November 2007, 14:21
  5. Replies: 12
    Last Post: 14th June 2006, 09:24

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.