Results 1 to 3 of 3

Thread: How to handle the value returned from a slot???

  1. #1
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default How to handle the value returned from a slot???

    After every second I want to get the cursor position. But I dont know how to obtain the value returned from a slot???
    Please help.
    Thanks in advance!

    Here is my code:

    Qt Code:
    1. QTimer *mtimer = new QTimer();
    2.  
    3. connect (mtimer, SIGNAL(timeout()), this, SLOT (get_cursor_position()));
    4.  
    5. QPoint MainWindow::get_cursor_position()
    6. {
    7. q = QCursor::pos();
    8. return q;
    9. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: How to handle the value returned from a slot???

    The return value is ignored when the slot is executed by a connection (by emitting a signal) - it can be used only when you call the like any other member function.

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

    learner_qt (10th February 2013)

  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: How to handle the value returned from a slot???

    You could emit a signal from slot, like
    Qt Code:
    1. QTimer *mtimer = new QTimer();
    2.  
    3. connect (mtimer, SIGNAL(timeout()), this, SLOT (get_cursor_position()));
    4.  
    5. QPoint MainWindow::get_cursor_position()
    6. {
    7. q = QCursor::pos();
    8. emit cursorChanged(p);
    9. }
    To copy to clipboard, switch view to plain text mode 
    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.

  5. The following 2 users say thank you to Santosh Reddy for this useful post:

    learner_qt (10th February 2013), Zlatomir (12th February 2013)

Similar Threads

  1. Replies: 8
    Last Post: 3rd May 2011, 23:47
  2. QList can't be returned
    By baluk in forum Newbie
    Replies: 18
    Last Post: 1st October 2010, 12:42
  3. slot sequence to handle http signals
    By ask8y@yahoo.com in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2010, 17:23
  4. QDateEdit and date returned
    By cydside in forum Qt Programming
    Replies: 17
    Last Post: 26th May 2009, 21:08
  5. SQLite - check if any records are returned
    By amicitas in forum Newbie
    Replies: 1
    Last Post: 28th September 2008, 10:28

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.