Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to concatenate a variable and two strings

How to concatenate a variable and two strings

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 8.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fs_tigre
    wrote on 1 Aug 2012, 20:06 last edited by
    #1

    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

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on 1 Aug 2012, 20:28 last edited by
      #2

      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()?)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fs_tigre
        wrote on 1 Aug 2012, 20:47 last edited by
        #3

        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 Reply Last reply
        0

        1/3

        1 Aug 2012, 20:06

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved