Results 1 to 8 of 8

Thread: Loading static images (png, jpeg) using QImage

  1. #1
    Join Date
    Mar 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Loading static images (png, jpeg) using QImage

    I am using Visual Studio 2015 with 32-bit Qt libraries which i built from qt-everywhere-src-5.12.0. Trying to load a static image using QImage.
    Receive the following message when i debug :
    QImage not loading, Error : <Information not available, no symbols loaded for Qt5Gui.dll>

    I tried the same approach in Qt creator and I am able to load the image.

    Have used the following code :
    Qt Code:
    1. void BqtOglCanvas::drawImage(int width, int height, BmRect imageRect)
    2. {
    3.  
    4. imgFlag = true;
    5.  
    6. resultSize = QSize(width, height);
    7. paintRect = QRect(QPoint(imageRect.pnt1.x, imageRect.pnt1.y), QPoint(imageRect.pnt2.x, imageRect.pnt2.y));
    8. }
    9.  
    10. QImage* BqtOglCanvas::loadImage(const QString &fileName, QImage *image) {
    11.  
    12. image->load(fileName);
    13.  
    14. *image = image->scaled(resultSize, Qt::KeepAspectRatio);
    15.  
    16. return image;
    17. }
    18.  
    19. QImage BqtOglCanvas::getSourceImage() {
    20. return sourceImage;
    21. }
    22.  
    23. void BqtOglCanvas::paintEvent(QPaintEvent *e)
    24. {
    25.  
    26. if (imgFlag) {
    27. imgFlag = false;
    28.  
    29. QImage sourceImage = getSourceImage();
    30.  
    31. QImage* img = loadImage("C:/Users/qu826e/Downloads/ply.png", &sourceImage);
    32.  
    33. const QRect imageRect = paintRect;
    34. const QImage resImage = *img;
    35. QPainter painter(this);
    36. painter.drawImage(imageRect, resImage);
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 

    Any leads will be really helpful.

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

    Default Re: Loading static images (png, jpeg) using QImage

    Receive the following message when i debug :
    QImage not loading, Error : <Information not available, no symbols loaded for Qt5Gui.dll>
    If you really are running a Debug version of your program, it should be reporting "Qt5GuiD.dll". Be sure you are linking with the correct libraries.

    QImage::load() returns a Boolean to indicate whether the load succeeded. Why don't you check it before trying to do anything more?

    Are you sure the fileName value points to the correct location on disk? Are you passing an absolute path or a relative path?

    Is a "image" a non-null pointer to a QImage? You can't call a class method through a null pointer, and "load" will not create a QImage instance.
    <=== 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.

  3. #3
    Join Date
    Mar 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Loading static images (png, jpeg) using QImage

    It's reporting Qt5Guid.dll. Have a doubt regarding the libraries. I built the lib using qt-everywhere-src-5.12.0 using the command : configure -debug -nomake examples -nomake tests -skip qtwebengine –opensource –opengl es2. Does this generate appropriate lib for QImage?

    QImage::load() returns a Boolean value true.

    fileName value points to the correct location on disk. it as an absolute path.

    QImage sourceImage = getSourceImage();
    sourceImage comes out to be null.

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading static images (png, jpeg) using QImage

    Quote Originally Posted by avinaskpai12 View Post
    QImage sourceImage = getSourceImage();
    sourceImage comes out to be null.
    Qt Code:
    1. QImage BqtOglCanvas::getSourceImage() {
    2. return sourceImage;
    3. }
    To copy to clipboard, switch view to plain text mode 

    Where do you fill this (member) variable?

  5. #5
    Join Date
    Mar 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Loading static images (png, jpeg) using QImage

    Qt Code:
    1. void BqtOglCanvas::drawImage(int width, int height, BmRect imageRect)
    2. {
    3.  
    4. imgFlag = true;
    5.  
    6. resultSize = QSize(width, height);
    7. QImage image(resultSize, QImage::Format_RGB32);
    8. sourceImage = image;
    9. paintRect = QRect(QPoint(imageRect.pnt1.x, imageRect.pnt1.y), QPoint(imageRect.pnt2.x, imageRect.pnt2.y));
    10. }
    To copy to clipboard, switch view to plain text mode 

    filling the variable in drawImage.

  6. #6
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading static images (png, jpeg) using QImage

    You create an empty (uninitialized) image with the size width/height and assign it to sourceImage. Nothing more.
    Last edited by ChristianEhrlicher; 31st March 2020 at 16:11.

  7. #7
    Join Date
    Mar 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Loading static images (png, jpeg) using QImage

    can you help me out with the steps to load the image?

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Loading static images (png, jpeg) using QImage

    It's pretty simple:

    Qt Code:
    1. QImage image;
    2. if ( image.load( filename ) )
    3. {
    4. // If you get here, the image was loaded successfully and is valid
    5. }
    6. else
    7. {
    8. // If you end up here, something went wrong
    9. }
    To copy to clipboard, switch view to plain text mode 
    <=== 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. Loading corrupt jpeg images with QImage
    By mikeee7 in forum Qt Programming
    Replies: 15
    Last Post: 3rd December 2010, 02:59
  2. about the Jpeg loading
    By iambeast in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 30th August 2010, 08:44
  3. QT Jpeg, Gif, Bmp loading issue
    By meraj ansari in forum Qt Programming
    Replies: 7
    Last Post: 21st May 2010, 09:33
  4. Replies: 4
    Last Post: 27th July 2009, 16:45
  5. Loading jpeg (QPixmap with Qt Jambi)
    By Mr_Blonde in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2006, 19:06

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.