Results 1 to 20 of 41

Thread: image not getting refreshed in Qlabel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: image not getting refreshed in Qlabel

    I have attached the minimal test case.
    Do have a look at the same
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: image not getting refreshed in Qlabel

    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,
    _

  3. #3
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: image not getting refreshed in Qlabel

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: image not getting refreshed in Qlabel

    Quote Originally Posted by prkhr4u View Post
    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 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,
    _

  5. #5
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: image not getting refreshed in Qlabel

    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.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: image not getting refreshed in Qlabel

    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.

  7. #7
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: image not getting refreshed in Qlabel

    I have connected the signal to slot in the main.cpp file.
    Here is the code:
    Qt Code:
    1. QObject::connect( & iThread, SIGNAL( ImageRefreshSignal(QImage) ),& dlg, SLOT( ImageRefreshSlot(QImage) ) );
    To copy to clipboard, switch view to plain text mode 
    I have checked it also,as inside the slot method the debug message "inside slot" is being printed.

    Even calling the connect method inside the MainWindow:: on_btn_dialog_clicked() does the same thing.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: image not getting refreshed in Qlabel

    Quote Originally Posted by prkhr4u View Post
    I have connected the signal to slot in the main.cpp file.
    Here is the code:
    Qt Code:
    1. QObject::connect( & iThread, SIGNAL( ImageRefreshSignal(QImage) ),& dlg, SLOT( ImageRefreshSlot(QImage) ) );
    To copy to clipboard, switch view to plain text mode 
    Yes, and it works as expected. The dialog shows all updates it gets from the thread.

    Quote Originally Posted by high_flyer View Post
    I have checked it also,as inside the slot method the debug message "inside slot" is being printed.
    Indeed it does.

    Quote Originally Posted by high_flyer View Post
    Even calling the connect method inside the MainWindow:: on_btn_dialog_clicked() does the same thing.
    Exactly! Connecting these other dialogs to the thread will make them update their label as well.

    Cheers,
    _

  9. #9
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: image not getting refreshed in Qlabel

    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?

  10. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: image not getting refreshed in Qlabel

    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.

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: image not getting refreshed in Qlabel

    Quote Originally Posted by prkhr4u View Post
    I had commented the dialog.show() in my test case.It Is not working as expected.
    It is. I tested it.

    Quote Originally Posted by prkhr4u View Post
    Comment out the line dialog.show() and then:
    When I click on the button in the main window,the dialog opens up
    No, a second dialog opens up.

    Quote Originally Posted by prkhr4u View Post
    and the label shows "Text label" and the image is not shown at all.
    As expected, that is what its code, generated from the designer UI file, is doing.

    Quote Originally Posted by prkhr4u View Post
    If I am showing the dialog at the start( uncommenting the dialog.show()),then it is working.
    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.


    Quote Originally Posted by prkhr4u View Post
    But I want the dialog to be open only after clicking the button.
    Then you need to connect the button to the dialog' show() slot, or use a slot that calls show() on the dialog.

    Cheers,
    _

Similar Threads

  1. Replies: 8
    Last Post: 6th November 2013, 03:36
  2. Checkboxes in Treeview do not get refreshed
    By mesch.t in forum Newbie
    Replies: 5
    Last Post: 13th April 2011, 20:53
  3. QTableView is not refreshed
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 13th October 2009, 21:23
  4. Replies: 6
    Last Post: 21st September 2009, 10:55
  5. QLabel as an image.
    By RSX in forum Newbie
    Replies: 2
    Last Post: 4th April 2009, 19:22

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
  •  
Qt is a trademark of The Qt Company.