Results 1 to 2 of 2

Thread: simple pixmap set path from std::string

  1. #1
    Join Date
    Apr 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question simple pixmap set path from std::string

    Dear Forum,
    i have a simple QLabel. Now i want to set an Image to this Label via Pixmap.

    This is working with an hardcoded path for example "data/image1.png".

    But if i try to set the pixmap path dynamically from an std::string i cant view this image and i get no errors.

    This is my Code:

    // working example hardcoded
    string path = "data/image1.png";
    QPixmap pixmap(path.c_str());
    ui->imageSite1->setPixmap(pixmap);

    BUT if i try to set the path dynamic as a function parameter for example, i cant view this image :-( .

    Code:

    string path = "data/"+imgfilepath; // parameter from methode
    QPixmap pixmap(path.c_str());

    Can anyone help me?
    Thanks in advanced.

    kenny

  2. #2
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: simple pixmap set path from std::string

    [Please use code-tags for your code]
    It should work. Can you give us the result of a
    Qt Code:
    1. qDebug ()<<path;
    To copy to clipboard, switch view to plain text mode 
    from before you actually open the pixmap? The difference of the respective results might explain the problem, which probably lies in the code you haven't shown. Btw: have you tried using sth. like
    Qt Code:
    1. QString::fromStdString
    To copy to clipboard, switch view to plain text mode 
    to convert your imgfilepath to a QString?

Similar Threads

  1. Replies: 5
    Last Post: 9th June 2015, 13:34
  2. Change plarform folder path to root folder path
    By Alundra in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2015, 23:53
  3. Replies: 8
    Last Post: 17th October 2009, 09:10
  4. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 09:51

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.