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
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: image not getting refreshed in Qlabel

    Yes but why do you need disk access ? Worker can process the image and send the processed result directly to the display thread, what's wrong with that
    now you have this:
    Qt Code:
    1. [load image from disk] --> process it --> [save to disk] --> inform gui that image is updated --> [load from disk] --> display
    To copy to clipboard, switch view to plain text mode 
    why not have this:
    Qt Code:
    1. [load image from disk] --> process it --> inform gui that image is updated, send the image via signal --> display
    To copy to clipboard, switch view to plain text mode 

  2. The following 2 users say thank you to stampede for this useful post:

    prkhr4u (9th December 2013)

  3. #2
    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

    Can you pl tell how to pass image via signal,I am unable to do so.

  4. #3
    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

    You add QImage as a parameter of the signal

    Qt Code:
    1. class GrabThread : public QThread
    2. {
    3. Q_OBJECT
    4.  
    5. signals:
    6. void ImageRefreshSignal(const QImage &image);
    7. };
    To copy to clipboard, switch view to plain text mode 
    And you pass the image at emit
    Qt Code:
    1. emit ImageRefreshSignal(image); // or image.copy() if the thread continues to use "image"
    To copy to clipboard, switch view to plain text mode 

    Similar signature changes to slot and connect obviously

    Cheers,
    _

  5. The following 2 users say thank you to anda_skoa for this useful post:

    prkhr4u (9th December 2013)

  6. #4
    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 done the changes and now am sending the image via signal,but still I am unable to refresh the image.
    Here is what I have done:
    Qt Code:
    1. class GrabThread : public QThread
    2. {
    3. Q_OBJECT
    4. private:
    5. void run();
    6. public:
    7. signals:
    8. void ImageRefreshSignal(const QImage &image);
    9. };
    To copy to clipboard, switch view to plain text mode 
    Signal emmited like:
    Qt Code:
    1. QImage img;
    2. img.load("abc.bmp");
    3. emit ImageRefreshSignal(img);
    To copy to clipboard, switch view to plain text mode 
    slot method called like:
    Qt Code:
    1. void Dialog_user::ImageRefreshSlot(QImage img )
    2. {
    3. qDebug()<<"inside slot";
    4. ui->label->setPixmap(QPixmap::fromImage(img));
    5. }
    To copy to clipboard, switch view to plain text mode 
    //dialog_user.h
    Qt Code:
    1. class Dialog_user : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit Dialog_user(QWidget *parent = 0);
    7. ~Dialog_user();
    8.  
    9. private slots:
    10. void ImageRefreshSlot (QImage img);
    To copy to clipboard, switch view to plain text mode 
    the connection is as follows:
    Qt Code:
    1. QObject::connect( & gthread, SIGNAL( ImageRefreshSignal(QImage) ),& d_user, SLOT( ImageRefreshSlot(QImage) ) );
    To copy to clipboard, switch view to plain text mode 
    I have checked the mechanism, and the message "inside slot" is being printed,but the image is not getting refreshed.

  7. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: image not getting refreshed in Qlabel

    Why do you load the image before sending it ? Can't you send the processed object ? Can we see the image processing code ?

  8. #6
    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 a separate image processing thread,which processes the image object as well as writes it to a bmp file "abc.bmp"
    The image processing is entirely different from GUI thread and works continuously in the background.
    As the GUI thread is only meant for display purposes,I am not sending the processed object for writing in GUI thread.

    Is there other way to send the image via a signal without loading it?

  9. #7
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: image not getting refreshed in Qlabel

    I have a separate image processing thread,which processes the image object as well as writes it to a bmp file "abc.bmp"
    The image processing is entirely different from GUI thread and works continuously in the background.
    As the GUI thread is only meant for display purposes,I am not sending the processed object for writing in GUI thread.
    Yes we know that ! Show us the code where you do this "abc.bmp" file writing in image processing thread. We want you to just emit the changed image apart from writing it to file. You have some image object on which you call save() method, right ? Just emit a signal, passing this object as parameter...

  10. #8
    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 main code for writing:
    Qt Code:
    1. void convert2bmp(unsigned int **Buffer_in,unsigned int x_size,unsigned int y_size,char *output_str)
    2. unsigned char* data3d = new unsigned char[x_size*y_size];
    3. fp = fopen (output_str, "wb");
    4. for ( i = x_size; i >= 0; i--)
    5. for (j = 0; j < y_size; j++)
    6. {
    7. data3d[k++]=Buffer_in[i][j];
    8. }
    9. fwrite( data3d, sizeof( char ),x_size*y_size, fp);
    10. fclose(fp);
    To copy to clipboard, switch view to plain text mode 

    Buffer_in: buffer containing the processed image data
    x_size,y_size: dimension of image
    Output_str: name of output file:"abc.bmp"

    After some image processing,which occurs on the buffer,I am writing it to a bitmap file.The Buffer_in is only available to me inside this(image processing thread) and then I am displaying the image in a Qlabel in GUI thread.
    The method "convert2bmp" is being called after every image processing iteration and the processed image needs to be displayed on a GUI thread everytime.
    But the image is not getting refreshed every time.

  11. #9
    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

    The variable k is used uninitialised.

    Just from looking at what you are doing to the image data I think it is exceptionally unlikely you have a valid BMP at the end of the process.
    Ignoring your GUI for a moment. Is the BMP file being written? Is it the correct size in bytes? Is it a valid BMP and can you see the right image in Microsoft Paint or something similar?

  12. #10
    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

    The bmp file is being written properly.
    I have excluded the code for bmp header and small variables like i,j,k.
    The code for main file writing is being enclosed.

  13. #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

    If Buffer_in is your pixel data, you can probably use it to create a QImage instance pointing to the same image data.

    And then use QImage::copy() to send it through the signal.

    Cheers,
    _

  14. #12
    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 sent the pixel data using QImage as follows:
    Qt Code:
    1. QImage myImage(400,700,QImage::Format_RGB888);
    2. for (int x=0;x<400;x++)
    3. for (int y=0;y<700;y++)
    4. myImage.setPixel(x,y,qRgb(Buffer_in[y][x*3],Buffer_in[y][x*3+1],Buffer_in[y][x*3+2]));
    5. emit ImageRefreshSignal(myImage.copy(0,0,400,700));
    To copy to clipboard, switch view to plain text mode 

    and used the slot as follows:
    Qt Code:
    1. void Dialog_user::ImageRefreshSlot(QImage img )
    2. {
    3. qDebug()<<"inside slot";
    4. ui->label->setPixmap(QPixmap::fromImage(img));
    5. }
    To copy to clipboard, switch view to plain text mode 

    still the label containg the image is not getting refreshed.
    The slot is being called correctly and the debug message "Inside slot" is being printed.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.