Results 1 to 9 of 9

Thread: Image loading

  1. #1
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Image loading

    Hi!

    I am trying to get the path top a QImage for my application.
    I did as followd:

    Qt Code:
    1. QPixmap image;
    2.  
    3. image.load(QCoreApplication::applicationDirPath() + "/Desktop/myImage");
    To copy to clipboard, switch view to plain text mode 

    My problem is that I can not load any image.

    What could be the problem? I will appreciate any help.

    Many thanks in advance.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCoreApplication

    Where is the image name ? "myImage.png" , myImage.jpg ?? which one ?

    Also what is the output of QCoreApplication::applicationDirPath() ?

  3. #3
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCoreApplication

    Many thanks aamer4yu for your reply.
    The image name should be myImage.png.
    Have a look please. When I proceed as followed, I do not need to add ".png", and I can have the image loaded. But I do not want to go this way.

    Qt Code:
    1. image.load("C:/Users/Desktop/myImage");
    To copy to clipboard, switch view to plain text mode 

    Even by writing myImage.png, there is no change.

    I have created a label on which th image should appear as followed:
    Qt Code:
    1. m_image = new QLabel(this);
    2. m_image->setPixmap(myImage);
    To copy to clipboard, switch view to plain text mode 
    Last edited by Stanfillirenfro; 15th January 2014 at 10:43.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCoreApplication

    Are you sure you know what QCoreApplication::applicationDirPath() returns ?

  5. #5
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCoreApplication

    Thanks Lesiok!

    Yes, QCoreApplication::applicationDirPath() returns the directory that contains the application executable.

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCoreApplication

    Please put a qDebug() for QCoreApplication::applicationDirPath() value...

  7. #7
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCoreApplication

    Thanks aamer4you for your reply.

    I am instead trying to proceed like this:
    Qt Code:
    1. QDir dir;
    2. dir.setCurrent("C:/Users/File/Desktop/imageFile");
    3. image.load(dir + "/myImage");
    To copy to clipboard, switch view to plain text mode 

    This does not function. Could you please have a lokk and give me an advice?

    Many thanks in advance.


    Added after 41 minutes:


    I have solved the problem.

    Many thanks for our help.
    Last edited by Stanfillirenfro; 15th January 2014 at 13:09.

  8. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCoreApplication

    Can You show us what is FULL path to file myImage and what is result of QCoreApplication::applicationDirPath() ?

  9. #9
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCoreApplication

    Hi Lesiok!
    Of courses!

    The initial idea was to load different images from a list, each image being represented by its name. So I had to get to the file in which the images are stored and to select an image. To be able to change the name of each image in the path, I thought I could use QCoreApplication::applicationDirPath(), but unfortunately I failed.

    I finally proceed as followed:

    Qt Code:
    1. QStringList listImages;
    2. QString str = "C:/Users/File/Desktop/imageFile/";
    3.  
    4. for(int i = 0; i<listImages.size(); i++)
    5. { if(listImages[i])
    6. str.append(listImages[i])
    7. image.load(str);
    8.  
    9. m_image = new QLabel(this);
    10. m_image->setPixmap(image);
    To copy to clipboard, switch view to plain text mode 

    On this way I could solve my problem.

    Thanks for your attention.

Similar Threads

  1. Loading Image
    By navi1084 in forum Qt Programming
    Replies: 2
    Last Post: 27th June 2011, 05:07
  2. Loading an image into memory
    By Luc4 in forum Qt Programming
    Replies: 6
    Last Post: 12th April 2010, 08:44
  3. loading image from disk
    By freekill in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2010, 05:21
  4. problems loading an image .jpg
    By maider in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2009, 11:57
  5. Image Loading
    By kavinsiva in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 08:00

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.