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.
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
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!
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.
Code:
class ControllerDialog
: public QObject {
public:
ControllerDialog(DialogRobot *dlgRobot);
public slots:
void sendSocketReceived() {
emit socketReceived();
}
signals:
void socketReceived(){};
private:
DialogRobot *dlg;
};
Here is the snippet of the connection, placed (quick&dirty) within the ControllerDialog Constructor:
Code:
QObject::connect(this,
SIGNAL(socketReceived
()),
dlgRobot, SLOT(robotSocketComplete()));
And this is the part of the QDialog:
Code:
public slots:
void on_btnStart_clicked();
void on_btnFinished_clicked();
void robotSocketComplete() { ... }
Problem is that connect() reports
Quote:
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 :)
Re: Give feedback to a QDialog from another thread
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!