-1

I have some pictures in the resource file and their file names correspond to their staffIds. this is how I set the picture into my QLabel but nothing is shown.

QString staffId;
staffId=ui->lineEdit_staffID->text();
QPixmap managerPic(":/staff/\'"+staffId+"\'.jpg");
managerInterface.ui->label_mpic->setScaledContents(true);
managerInterface.ui->label_mpic->setPixmap(managerPic);
Mike
  • 8,055
  • 1
  • 30
  • 44
  • 5
    why are you putting `\'` characters before and after the `staffId` string? does your filename contain single-quote characters??? – Mike Jun 06 '16 at 05:30

1 Answers1

0

I'm with @Mike here, most probably the single quotes aren't part of your filenames. You can use the debugger to see what is passed to the QPixmap constructor, or put the name into a separate QString variable and write it to qDebug() to see what it contains.

In general you better use QString::arg() to build strings instead of concatenation; usually it's easier to read and understand:

QPixmap managerPic(QString(":/staff/\'%1\'.jpg").arg(staffId));
QPixmap managerPic(QString(":/staff/%1.jpg").arg(staffId));
Murphy
  • 3,827
  • 4
  • 21
  • 35