How to concatenate a variable and two strings
-
wrote on 1 Aug 2012, 20:06 last edited by
Hi,
I'm trying to concatenate a variable (QString) and two other strings. What I have is a lineEdit and a button, when the button is clicked it should concatenate the content in the lineEdit to the file path and also the .pdf extension and finally open the specified .pdf file.
This is what I have but it doesn't work.
@QString fileName;
fileName = ui->lineEdit->text();
QDesktopServices::openUrl(QUrl("file:///P:/test/file/" + fileName + ".pdf") );@
When I qDebug fileName inside the click event I get an empty string "".
Thanks
-
wrote on 1 Aug 2012, 20:28 last edited by
Try
@QString("file:///P:/test/file/%1.pdf").arg(fileName)@Although I'm not sure what the problem is in your case. Normally concatenating QStrings with the + operator works...
bq. When I qDebug fileName inside the click event I get an empty string “”.
Then your lineEdit is empty. (Or did you print the value before assigning it the lineEdit->text()?)
-
wrote on 1 Aug 2012, 20:47 last edited by
bq. Then your lineEdit is empty. (Or did you print the value before assigning it the lineEdit->text()?)
As always you guys are right, it was my lineEdit.
You guys are awesome!
1/3