Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[solved] Signals and Slots ... again
I have read so many threads, wikis and so on for Signals and Slots but I still can't make it work in my app.
I'm not even sure that the logic of my app is OK. So here is the logic:
- I have a class 'downloader' which connects to Internet and download some things;
- another class 'sumcclient' which using some logic ask the downloader to give it some info from Internet
- I have a QTextEdit in which I want to publish the downloaded info.
What I'm doing:
When the program starts:
connect( &sumc, SIGNAL( contentReady(QString) ), ui->uiInformation, SLOT( insertHtml(QString) ));@
contentReady is emitted in the sumclient class when the information is downloaded: @connect( down, SIGNAL( downloaded(QString) ) , this, SIGNAL( contentReady(QString) ));@
and info is downloaded when: @connect( reply, SIGNAL( finished() ), this, SLOT( finishedDownload() ) );@
in finishedDownload() it is emitted "download(QString)" signal where the QString should be the info.
The problem is that the signals and slots stop communicating ( I'm doing something wrong .. of course ):
QNetworkReply is sent and received -> then finished() signal is emitted and finishDownload() is called
in finishDownload() it is emitted 'Downloaded(QString)' signal
then I suppose that 'contentReady(QString)' should be emittted with the same content as 'Downloaded(QSting)'
and then as this signal is connected to the 'insertHtml(QString)' slot of the QTextEdit ... I want the info to appear into the TextEdit.
The whole source of the app is in this "git repo":https://github.com/SecretNinja/OnTime . Is it needed to clarify my question?
Thank you :)
Franzk last edited by
The code in your github repo doesn't have the signals yet. Your connect statements will tell you the connection has therefore failed.
I'm sorry ... I thought that it was committed. Now there is commit named "Signals and Slots".
The main difference is in this files:
Franzk last edited by
Do you get any Object::connect messages in your application output while debugging?
This is all the output I have:
startRequest() for "http://m.sumc.bg/vt?q=1287&go=1"
finishedDownload() for "http://m.sumc.bg/vt?q=1287&go=1"
C:\Coding\Qt\OnTime-build-simulator\debug\OnTime.exe exited with code 0@
leon.anavi last edited by
I had a quick glance at your code. I saw that you emit downloaded successfully. Signal downloaded is connected to signal contentReady and in MainWindow contentReady is connected to slot insertHtml, right?
Is the contentReady signal also emitted successfully? Is everything with the QTextEdit ui->uiInformation OK?
Yes, that's right.
As you said downloaded is connected to contentReady and it should be emitted but I think this is the place where something goes wrong.
It seems to me that there is no problem with the QTextEdit:
- manually I could set its content;
- I create another signal ( and connected it with insertHtml ) in sumcClient class ( contentReady is there too ) and emitted it with some text and it is displayed in the QTextEdit.
So this is the problem:
@connect( down, SIGNAL( downloaded(QString)) , this, SIGNAL(contentReady(QString)));@
If downloaded is emitted, why contentReady is not?
OK ... I've just solved my issue. I am still not sure exactly which of the things I changed help me.
I will test a little bit more and will write what the problem was.
Thank you :) Explaining my problem and the question you've asked me made me think what and where is the problem :)