0

My image does not appear :

QString champ("C:/champions/" + ui->comboBox->currentText() + "_1.jpg");
QPixmap image(champ);


ui->label_1->setPixmap(QPixmap(image));

I tried to solve this for 2 hours. Help me please ! Sorry if my english is bad because i'm french ^^ .

  • First check the content of 'champ' and check that it's a valid path. Then check that the pixmap could be loaded, by using QPixmap::load and checking the return value. – Frank Osterfeld Jun 09 '13 at 08:31

1 Answers1

0

Qt QPixmap pointer limit

http://qt-project.org/doc/qt-5.0/qtgui/qpixmap.html#details

Like I mentioned in the answer above, use

bool retVal = QPixmap::load(champ);

Then check the retVal to see what happened.

if(retVal == false)
{
    qDebug() << "These are the supported formats:" 
             << QImageReader::supportedImageFormats();
    if(QFile::exists(champ) == false)
    {
        qDebug() << "Unable to find file" << champ;
    }
}

Also make sure that your QPixmap isn't going out of scope. So put it as a member function in your header file. Otherwise it may not exist at the end of your constructor.

http://qt-project.org/doc/qt-5.0/qtgui/qimagereader.html#supportedImageFormats

http://qt-project.org/doc/qt-5.0/qtcore/qfile.html#exists

Hope that helps.

Community
  • 1
  • 1
phyatt
  • 18,472
  • 5
  • 61
  • 80