PDA

View Full Version : simple pixmap set path from std::string



kenny
29th April 2017, 14:25
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

sedi
30th April 2017, 08:01
[Please use code-tags for your code]
It should work. Can you give us the result of a

qDebug ()<<path;
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
QString::fromStdString to convert your imgfilepath to a QString?