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. Putting double quotes around a QString variable?
Forum Updated to NodeBB v4.3 + New Features

Putting double quotes around a QString variable?

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 5 Posters 4.6k Views 1 Watching
  • 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.
  • ElusE Offline
    ElusE Offline
    Elus
    wrote on last edited by
    #13

    @Elus said in Putting double quotes around a QString variable?:

    deploystring = "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe "C:/Users/wjbro/Desktop/New folder/Release001.exe"";
    process->startDetached("cmd /c "" + deploystring);

    I think carets are sometimes used in Windows to escape spaces, no?

    deploystring = "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe \"C:/Users/wjbro/Desktop/New^ folder/Release001.exe\"";        
    process->startDetached("cmd /c \"" + deploystring);   
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #14

      For me the right concatenation sentence is:
      process->startDetached("cmd /c " + deploystring);

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Darkloud
        wrote on last edited by
        #15

        None of these work... :( Heading to bed. Will try again tomorrow

        B 1 Reply Last reply
        0
        • D Darkloud

          None of these work... :( Heading to bed. Will try again tomorrow

          B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #16

          @Darkloud Do you actually try @mpergand 's advice? I also think the problem is that extra \" after cmd /c.
          And since you've struggled a lot with quotes, why don't you just use program + arguments as params?

          process->startDetached("cmd", QStringList() << "/c" << "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" << "C:/Users/wjbro/Desktop/New folder/Release001.exe");   
          

          Then you won't need to add extra quotes to paths.

          JonBJ D 2 Replies Last reply
          5
          • B Bonnie

            @Darkloud Do you actually try @mpergand 's advice? I also think the problem is that extra \" after cmd /c.
            And since you've struggled a lot with quotes, why don't you just use program + arguments as params?

            process->startDetached("cmd", QStringList() << "/c" << "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" << "C:/Users/wjbro/Desktop/New folder/Release001.exe");   
            

            Then you won't need to add extra quotes to paths.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #17

            @Bonnie
            I think @Darkloud should indeed run the process via the QStringList() overload you suggest.

            However, personally I would call QString QDir::toNativeSeparators(const QString &pathName) (https://doc.qt.io/qt-5/qdir.html#toNativeSeparators) on each of those file path arguments. Unless windeployqt.exe states that it wants file paths to be passed with forward slashes, relying on Windows programs to treat / as the same as \ is dubious, IMHO. Although not this example, I have said before look at the difference between, say, dir /w versus dir \w, which do not do the same thing!

            1 Reply Last reply
            1
            • B Bonnie

              @Darkloud Do you actually try @mpergand 's advice? I also think the problem is that extra \" after cmd /c.
              And since you've struggled a lot with quotes, why don't you just use program + arguments as params?

              process->startDetached("cmd", QStringList() << "/c" << "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" << "C:/Users/wjbro/Desktop/New folder/Release001.exe");   
              

              Then you won't need to add extra quotes to paths.

              D Offline
              D Offline
              Darkloud
              wrote on last edited by
              #18

              @Bonnie said in Putting double quotes around a QString variable?:

              @Darkloud Do you actually try @mpergand 's advice? I also think the problem is that extra \" after cmd /c.
              And since you've struggled a lot with quotes, why don't you just use program + arguments as params?

              process->startDetached("cmd", QStringList() << "/c" << "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" << "C:/Users/wjbro/Desktop/New folder/Release001.exe");   
              

              Then you won't need to add extra quotes to paths.

              Yes I did... However it was still not working for me, as stated... However your solution worked! During my research last night, I found using QStringList() was a cleaner and safer way of passing arguments to the command line, however I suppose I was implementing it inorrectly. Not sure what I did incorrectly, but after taking the line you suggested and substituting the hard coded directories with my variables "exeName and binFolderName like so:

              ```
              

              process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);

              
              Everything is working as it should!
              
              Thank you all for the help!
              1 Reply Last reply
              0
              • D Offline
                D Offline
                Darkloud
                wrote on last edited by Darkloud
                #19

                @Darkloud said in Putting double quotes around a QString variable?:

                process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);

                Actually, it isn't working... I thought it was, but I am still getting the same error :/

                If I run:

                ```
                

                process->startDetached("cmd", QStringList() << "/c" << "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" << "C:/Users/wjbro/Desktop/New folder/Release001.exe");

                it works correctly. If I run:
                
                    ```
                process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);
                

                it gives me the same
                " C:\Users\wjbro\Desktop\New" does not exist.
                error

                Here is my whole .cpp file if it helps:

                #include "deployqt.h"
                #include "ui_deployqt.h"
                #include <QDebug>
                
                
                
                DeployQt::DeployQt(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::DeployQt)
                {
                    ui->setupUi(this);
                }
                
                DeployQt::~DeployQt()
                {
                    delete ui;
                }
                
                void DeployQt::on_CancelButton_clicked()
                {
                    this->close();
                }
                
                
                void DeployQt::on_QtBinDirBrowse_clicked()
                {
                    binFolderName = QFileDialog::getExistingDirectory(this,       // Open folder select dialog, default to 5.14.2\mingw73_64\bin, store in binFolderName
                        tr("Open Bin Directory"), "C:\\Qt\\5.14.2\\mingw73_64\\bin",QFileDialog::DontResolveSymlinks);
                
                   if(!binFolderName.isEmpty()){        // If binFolderName is not empty, set it to QtBindirOut LineOutput
                           ui->QtBinDirOut->setText(binFolderName);
                           binFolderName = binFolderName + "/windeployqt.exe "; // append /windeployqt.exe to binFolderName
                }
                }
                
                
                void DeployQt::on_QtInputExeBrowse_clicked()
                {
                    exeName = QFileDialog::getOpenFileName(this,      // Open exe to be deployed select dialog, sets to exeName
                         tr("Select Exe to Deploy"), "C:\\");
                
                    if(!exeName.isEmpty()){                // If exeName is not empty, set it to QtInputExeOut LineOutput
                            ui->QtInputExeOut->setText(exeName);
                 }
                }
                
                
                void DeployQt::on_DeployButton_clicked()
                {
                    QProcess *process = new QProcess(this);
                    ui->statusbar->showMessage("Running: " + binFolderName + exeName);         // Set status bar message to reflect running command
                    process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);
                
                    if ( !process->waitForFinished(-1))    // Wait for process to finish
                    {
                        return;                            // Return from if statement, to continue
                    }
                
                
                
                    if(process->exitCode() != 0){
                        QString errorMessage;
                        if(binFolderName == ""){
                            errorMessage.append("No Bin Folder Selected!\n");
                        }
                
                        if(exeName == ""){
                            errorMessage.append("No Exe File Selected! ");
                        }
                
                        msgBox.setText(errorMessage);
                        msgBox.setWindowTitle("Error - Deploy Qt Exe (Windows)");
                        msgBox.exec();
                    }
                
                    else{
                        ui->statusbar->showMessage("Complete!");
                    }
                
                
                }
                

                Really not sure what happened.. Could have sworn I tested it and it worked fine.

                EDIT: facepalm In order to get the QString to display correctly in the status bar with a space between binFolderName and exeFile, i put a space after the /windeploy append.. That was my issue! Working fine!

                JonBJ 1 Reply Last reply
                0
                • D Darkloud

                  @Darkloud said in Putting double quotes around a QString variable?:

                  process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);

                  Actually, it isn't working... I thought it was, but I am still getting the same error :/

                  If I run:

                  ```
                  

                  process->startDetached("cmd", QStringList() << "/c" << "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" << "C:/Users/wjbro/Desktop/New folder/Release001.exe");

                  it works correctly. If I run:
                  
                      ```
                  process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);
                  

                  it gives me the same
                  " C:\Users\wjbro\Desktop\New" does not exist.
                  error

                  Here is my whole .cpp file if it helps:

                  #include "deployqt.h"
                  #include "ui_deployqt.h"
                  #include <QDebug>
                  
                  
                  
                  DeployQt::DeployQt(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::DeployQt)
                  {
                      ui->setupUi(this);
                  }
                  
                  DeployQt::~DeployQt()
                  {
                      delete ui;
                  }
                  
                  void DeployQt::on_CancelButton_clicked()
                  {
                      this->close();
                  }
                  
                  
                  void DeployQt::on_QtBinDirBrowse_clicked()
                  {
                      binFolderName = QFileDialog::getExistingDirectory(this,       // Open folder select dialog, default to 5.14.2\mingw73_64\bin, store in binFolderName
                          tr("Open Bin Directory"), "C:\\Qt\\5.14.2\\mingw73_64\\bin",QFileDialog::DontResolveSymlinks);
                  
                     if(!binFolderName.isEmpty()){        // If binFolderName is not empty, set it to QtBindirOut LineOutput
                             ui->QtBinDirOut->setText(binFolderName);
                             binFolderName = binFolderName + "/windeployqt.exe "; // append /windeployqt.exe to binFolderName
                  }
                  }
                  
                  
                  void DeployQt::on_QtInputExeBrowse_clicked()
                  {
                      exeName = QFileDialog::getOpenFileName(this,      // Open exe to be deployed select dialog, sets to exeName
                           tr("Select Exe to Deploy"), "C:\\");
                  
                      if(!exeName.isEmpty()){                // If exeName is not empty, set it to QtInputExeOut LineOutput
                              ui->QtInputExeOut->setText(exeName);
                   }
                  }
                  
                  
                  void DeployQt::on_DeployButton_clicked()
                  {
                      QProcess *process = new QProcess(this);
                      ui->statusbar->showMessage("Running: " + binFolderName + exeName);         // Set status bar message to reflect running command
                      process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);
                  
                      if ( !process->waitForFinished(-1))    // Wait for process to finish
                      {
                          return;                            // Return from if statement, to continue
                      }
                  
                  
                  
                      if(process->exitCode() != 0){
                          QString errorMessage;
                          if(binFolderName == ""){
                              errorMessage.append("No Bin Folder Selected!\n");
                          }
                  
                          if(exeName == ""){
                              errorMessage.append("No Exe File Selected! ");
                          }
                  
                          msgBox.setText(errorMessage);
                          msgBox.setWindowTitle("Error - Deploy Qt Exe (Windows)");
                          msgBox.exec();
                      }
                  
                      else{
                          ui->statusbar->showMessage("Complete!");
                      }
                  
                  
                  }
                  

                  Really not sure what happened.. Could have sworn I tested it and it worked fine.

                  EDIT: facepalm In order to get the QString to display correctly in the status bar with a space between binFolderName and exeFile, i put a space after the /windeploy append.. That was my issue! Working fine!

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #20

                  @Darkloud said in Putting double quotes around a QString variable?:

                  process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);

                  So qDebug() << binFolderName and qDebug() << exeName, and copy & paste so that we can clearly read them. If they were identical to your original "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" & "C:/Users/wjbro/Desktop/New folder/Release001.exe", then it would behave the same, there's nothing magical about literal strings vs variables.

                  D 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Darkloud said in Putting double quotes around a QString variable?:

                    process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);

                    So qDebug() << binFolderName and qDebug() << exeName, and copy & paste so that we can clearly read them. If they were identical to your original "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" & "C:/Users/wjbro/Desktop/New folder/Release001.exe", then it would behave the same, there's nothing magical about literal strings vs variables.

                    D Offline
                    D Offline
                    Darkloud
                    wrote on last edited by
                    #21

                    @JonB said in Putting double quotes around a QString variable?:

                    @Darkloud said in Putting double quotes around a QString variable?:

                    process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);

                    So qDebug() << binFolderName and qDebug() << exeName, and copy & paste so that we can clearly read them. If they were identical to your original "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" & "C:/Users/wjbro/Desktop/New folder/Release001.exe", then it would behave the same, there's nothing magical about literal strings vs variables.

                    See above! I added a space after the first argument, which messed everything up. It is working now!

                    JonBJ 1 Reply Last reply
                    0
                    • D Darkloud

                      @JonB said in Putting double quotes around a QString variable?:

                      @Darkloud said in Putting double quotes around a QString variable?:

                      process->startDetached("cmd", QStringList() << "/c" << binFolderName << exeName);

                      So qDebug() << binFolderName and qDebug() << exeName, and copy & paste so that we can clearly read them. If they were identical to your original "C:/Qt/5.14.2/mingw73_64/bin/windeployqt.exe" & "C:/Users/wjbro/Desktop/New folder/Release001.exe", then it would behave the same, there's nothing magical about literal strings vs variables.

                      See above! I added a space after the first argument, which messed everything up. It is working now!

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #22

                      @Darkloud
                      Yeah, I think you discovered/typed that while I was answering. Gotta love them spaces... :)

                      1 Reply Last reply
                      0

                      • Login

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