I have attached the minimal test case.
Do have a look at the same
I have attached the minimal test case.
Do have a look at the same
Your code works nicely (after uncommenting the dialog's show() call of course, can display something that is hidden)
The image thread emits the image and the dialog it is connected to gets the slot invocation and displays the image.
I modified the thread's run() method it randomly use a different color and indeed those changes are visible in the dialog connected to the thread.
Cheers,
_
I know that this way it is working,but I want to show the dialog only after clicking the button "go to dialog" from main window.In that case it is not working.
I suspect this is due to the event loop not closing,but I am unable to close it and hence the label is not working.
Similarly there is some login code in main window,after clicking login button,the dialog opens up and I want to show the image in the label.The label is then unable to set the image at that moment.
I have tried with both QImage and bitmap image.In both the cases,the QLabel is unable to show the image.
I don't see why this would not also work.
Why didn't you put that into the testcase?
Right now your code does exactly what it is supposed to do. The thread emits the image, the label in the connected dialog is updated.
There is a button which opens another dialog and it also shows its label content as expected.
The event loop is nicely running. If the thread is modified to emit images in a loop, the label in the dialog it is connected to will change every time there is a new image.
Cheers,
_
I had commented the dialog.show() in my test case.It Is not working as expected.
Comment out the line dialog.show() and then:
When I click on the button in the main window,the dialog opens up and the label shows "Text label" and the image is not shown at all.
If I am showing the dialog at the start( uncommenting the dialog.show()),then it is working.But I want the dialog to be open only after clicking the button.
You never connect the signal from the thread to the dialog you create in the MainWindow::on_btn_dialog_clicked(). Why would you expect it to update?
(The way your code is written the thread object is not available to be connected in this routine anyway.)
Last edited by ChrisW67; 23rd December 2013 at 03:33.
I have connected the signal to slot in the main.cpp file.
Here is the code:
I have checked it also,as inside the slot method the debug message "inside slot" is being printed.Qt Code:
To copy to clipboard, switch view to plain text mode
Even calling the connect method inside the MainWindow:: on_btn_dialog_clicked() does the same thing.
Yes, and it works as expected. The dialog shows all updates it gets from the thread.
Indeed it does.
Exactly! Connecting these other dialogs to the thread will make them update their label as well.
Cheers,
_
Here is the sequence of events I want:
load main window,start image processing thread -> click on button 'go to dialog' -> open a new dialog -> refresh image(QImage from thread via signal-slot) in Qlabel in new dialog
Here is what is happening:
load main window,start image processing thread -> click on button 'go to dialog' -> open a new dialog -> Qlabel showing only 'Text Label' and image is not loaded.
Only the dialogs which start from main can interact with the thread and can update themselves with the thread,but In my case the dialog is opening from main window and is not able to interact with the thread.
pl suggest how to overcome this problem?
Is there any design changes I have to do?
You have been told several times what needs to be done: connect the dialog slot to the signal providing the update. The dialog you launch in response to the button press is never going to update unless you connect it to something that is going to cause it to update. It really is that simple. You will have to arrange your program so that this connection can be made, and then you have to code that connection.
The instance of the dialog you create in main() and connect to the output of your thread has nothing to do with the instance of the dialog you create in the button slot, which remains connected to nothing.
"We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.
It is. I tested it.
No, a second dialog opens up.
As expected, that is what its code, generated from the designer UI file, is doing.
No, time of showing has nothing to do with that.
You have two places were you create dialog instances. One in main() and one in the main window's slot.
The instance from main() is connected to the thread and updates its label when ever there is a new image. Any instance created from the main window's slot has no interaction after it has been created and thus shows whatever you had in its UI file.
Then you need to connect the button to the dialog' show() slot, or use a slot that calls show() on the dialog.
Cheers,
_
Bookmarks