Results 1 to 6 of 6

Thread: Give feedback to a QDialog from another thread

  1. #1
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Give feedback to a QDialog from another thread

    Hi!

    I am new to Qt developement so this might be a very easy question for the experts out there

    A have serveral C++ Classes handling a socket connection with a remote device. These Classes are part of an older Framework we developed some time ago (so there is no inheritance from QObject etc.).
    The application has a few threads and one of them should "inform" the GUI about a certain event.

    There is a QT-Dialog Window waiting for this information. So I guess, as far as I understood, I could generate a signal to solved this?!
    As long as my class is not based on a QObject (and I don't want to change that) I could need some kind of model-view-controller structure. So that the signal can be generated by the controller?!

    May be there is a much simpler way to achieve my goal of sending a signal to the GUI by my thread?!
    Would be perfect, I somebody could help me out
    Thank you!

    J.R.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Give feedback to a QDialog from another thread

    what about just creating a simple QObject class which works as a signal thrower.. make an your thread call some public function of the class which in turn emits the relevant signal to gui

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

    JohnnyRep (8th March 2010)

  4. #3
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Give feedback to a QDialog from another thread

    Hey!
    Thx for your answer.
    That would be in a way a smaller version of my idea of using a model-view-controller pattern. I just wondered whether Qt offers a direct way to receive signals from a "foreign" non-Qt class!
    Thanks again!

  5. #4
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Give feedback to a QDialog from another thread

    Now I got stuck by using your way of solving the problem:

    3 Classes (A non-Qt, a small QObject class and a QDialog)... Idea is that the non-Qt class can report something to the dialog by using signals.

    This is the small QObject class which should create a signal and call a slot in the dialog class.
    Qt Code:
    1. class ControllerDialog : public QObject {
    2.  
    3. public:
    4. ControllerDialog(DialogRobot *dlgRobot);
    5.  
    6. public slots:
    7. void sendSocketReceived() {
    8. emit socketReceived();
    9. }
    10. signals:
    11. void socketReceived(){};
    12.  
    13. private:
    14. DialogRobot *dlg;
    15.  
    16. };
    To copy to clipboard, switch view to plain text mode 

    Here is the snippet of the connection, placed (quick&dirty) within the ControllerDialog Constructor:
    Qt Code:
    1. QObject::connect(this, SIGNAL(socketReceived()),
    2. dlgRobot, SLOT(robotSocketComplete()));
    To copy to clipboard, switch view to plain text mode 

    And this is the part of the QDialog:
    Qt Code:
    1. public slots:
    2. void on_btnStart_clicked();
    3. void on_btnFinished_clicked();
    4. void robotSocketComplete() { ... }
    To copy to clipboard, switch view to plain text mode 

    Problem is that connect() reports
    Object::connect: No such signal QObject::socketReceived() in src/draw/Qt/controller/controller_dialog.cpp:12
    Object::connect: (receiver name: 'DialogRobotClass')
    I used the search function of the forum and googled now for quite a while... And I found several HowTo's etc., but I don't see any bigger difference between my code and the samples

    I used connect() successfully for connecting Button-Events etc., but in this case I don't see the problem

  6. #5
    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: Give feedback to a QDialog from another thread

    Use the Q_OBJECT macro!

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

    JohnnyRep (8th March 2010)

  8. #6
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Give feedback to a QDialog from another thread

    Small macro -> big difference

    Thanks for your quick help guys, it really helped me a lot!

Similar Threads

  1. QDialog with QPainter in new thread
    By grucha in forum Qt Programming
    Replies: 0
    Last Post: 21st November 2009, 23:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.