Results 1 to 2 of 2

Thread: QT label update. Different threads.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QT label update. Different threads.

    I don't see any call to main_window->show() in your main(). That should happen just before app.exec().

    Edit: Your code is extremely confused. I see now that you call show() in createWidgets(), but this method is commented out.

    And this code:

    Qt Code:
    1. this->camera_1 = &QImage(img);
    2. this->camera_2 = &QImage(img);
    To copy to clipboard, switch view to plain text mode 

    is totally wrong. You are creating two QImage instances -on the stack (QImage(img))- and these instance are destroyed immediately when your method exits. So camera_1 and camera_2 are assigned pointer values which become invalid and dangling as soon as the method is done.

    To do this correctly, you could change camera_1 and camera_2 from being QImage * to simply QImage and just assign the incoming image to them:

    Qt Code:
    1. // .h:
    2.  
    3. QImage camera_1;
    4. QImage camera_2;
    5.  
    6. // .cpp:
    7.  
    8. this->camera_1 = img;
    9. this->camera_2 = img;
    To copy to clipboard, switch view to plain text mode 

    The same error occurs here:

    Qt Code:
    1. this->cam1 = &tmp_label;
    2. this->cam2 = &tmp_label;
    To copy to clipboard, switch view to plain text mode 

    You are assigning the address of a temporary QLabel variable which gets destroyed as soon as the method exits, so cam1 and cam2 end up pointing to a non-existent QLabel instance.

    You need to go back to your C++ textbook and read about variables and scoping.
    Last edited by d_stranz; 22nd March 2017 at 03:17.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 9th September 2015, 18:06
  2. Threads, Timer and Update a Field
    By lima_will in forum Newbie
    Replies: 2
    Last Post: 2nd October 2013, 08:05
  3. Update GUI from another object with 2 threads.
    By jiapei100 in forum Qt Programming
    Replies: 8
    Last Post: 19th February 2013, 17:27
  4. unable to update label from another thread
    By dhanya.v in forum Qt Programming
    Replies: 1
    Last Post: 4th October 2012, 12:05
  5. How to update GUI promptly with data sent from threads
    By Eos Pengwern in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2010, 11:33

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.