Results 1 to 5 of 5

Thread: SLOT fires only on mouse move

  1. #1
    Join Date
    Jan 2011
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question SLOT fires only on mouse move

    I've this code ... stripped a bit
    Qt Code:
    1. void testform::keyPressEvent(QKeyEvent *event)
    2. {
    3. switch (event->key())
    4. {
    5. case Qt::Key_4 :
    6. if (!demo_started)
    7. {
    8. this->buttons[0]->setPixmap(QPixmap::fromImage(images[1]));
    9. this->listener = new PortListener(portName);
    10.  
    11. // So, connect to listener, and ... all happy :P
    12. connect(this->listener,SIGNAL(packet_received(data_answer)),
    13. this,SLOT(packet_received(data_answer)));
    14.  
    15. }
    16. else
    17. {
    18. this->buttons[0]->setPixmap(QPixmap::fromImage(images[0]));
    19. this->killTimer(demo_timer_id)
    20. }
    21. demo_started = !demo_started;
    22. break;
    23. ...................................
    24. default : QWidget::keyPressEvent(event);
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    and receiver SLOT:
    Qt Code:
    1. void testform::packet_received(data_answer answer)
    2. {
    3. qDebug() << "pewpew all dead !";
    4. redrawUI();
    5. }
    To copy to clipboard, switch view to plain text mode 

    Problem is that this slot called only when I move mouse,press key etc. But signal itself emmited every 0.5 seconds (read data from com-port). Listener class is quite stable and works as intended.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SLOT fires only on mouse move

    Problem is that this slot called only when I move mouse,press key etc. But signal itself emmited every 0.5 seconds
    Do you mean it only starts to be called after you have pressed a key (but then regularly gets called after that), or only when you press a key the slot is called?
    Do you use diconnect() in your code anywhere, or delete the listener?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2011
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SLOT fires only on mouse move

    no, no disconnect() anywhere.
    I checked with debugger, and even signal doesn't emitted unless I click on window, or press button. And yes, it's emitted only when i push/click.
    Listener instance deleted in desctructor.

    tryReceive() called in listener constructor first time, and then recalled with floating window.
    Qt Code:
    1. void PortListener::tryReceive(){
    2. if(this->port->bytesAvailable()>0){
    3. timeout = qMax(100, timeout/2);
    4. myRcvBuffer.clear();
    5. myRcvBuffer.append(port->readAll());
    6. qDebug() << "bytes read:" << myRcvBuffer.length();
    7. qDebug() << "bytes:" << myRcvBuffer;
    8. last_packet = Hemofenix_protocol::decode_packet(myRcvBuffer);
    9. emit packet_received(last_packet);
    10. } else {
    11. timeout = qMin(1000, timeout*2);
    12. }
    13. QTimer::singleShot(timeout, this, SLOT(tryReceive()));
    14. }
    To copy to clipboard, switch view to plain text mode 

    I put some qDebug() output there, but it do output only on user actions

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SLOT fires only on mouse move

    But signal itself emmited every 0.5 seconds
    Your posted code does not supports this assertion.
    Your packet_received signal is only emitted when bayteAvailble()>0 is true however.
    So it seems that for some reason bytesAvalable() returns 0 or less unless you press a key.
    This sounds like a busy loop problem somewhere in your code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2011
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SLOT fires only on mouse move

    Mystics ... I left code untouched for weekend, compiled today and it works like a charm. Really wired.
    Thanks for replys.

Similar Threads

  1. disable mouse move
    By karlkar in forum Newbie
    Replies: 0
    Last Post: 4th January 2011, 19:47
  2. How to move the mouse ?
    By shad0w in forum Newbie
    Replies: 3
    Last Post: 2nd November 2008, 13:55
  3. Move mouse over object
    By ToddAtWSU in forum Qt Programming
    Replies: 17
    Last Post: 3rd October 2007, 15:53
  4. Mouse Move Event
    By merry in forum Newbie
    Replies: 5
    Last Post: 3rd June 2007, 06:26
  5. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 05:34

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.