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. QString replace %U
QtWS25 Last Chance

QString replace %U

Scheduled Pinned Locked Moved Solved General and Desktop
41 Posts 5 Posters 8.6k 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.
  • S sonichy
    26 Oct 2021, 08:46

    @JonB deepin-draw "/home/sonichy/Desktop/KuGou.png"

    J Offline
    J Offline
    JonB
    wrote on 26 Oct 2021, 08:56 last edited by JonB
    #26

    @sonichy said in QString replace %U:

    @JonB deepin-draw "/home/sonichy/Desktop/KuGou.png"

    I previously wrote:

    Is sExec set to the correct full path to the executable? What do you think your process->setWorkingDirectory(path); achieves? Because if you think it is used to locate the executable to run, it is not.

    J S 2 Replies Last reply 26 Oct 2021, 08:58
    0
    • J JonB
      26 Oct 2021, 08:56

      @sonichy said in QString replace %U:

      @JonB deepin-draw "/home/sonichy/Desktop/KuGou.png"

      I previously wrote:

      Is sExec set to the correct full path to the executable? What do you think your process->setWorkingDirectory(path); achieves? Because if you think it is used to locate the executable to run, it is not.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 26 Oct 2021, 08:58 last edited by
      #27

      @JonB Yes, it is said that people often do not read carefully...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply 26 Oct 2021, 09:00
      1
      • J jsulm
        26 Oct 2021, 08:58

        @JonB Yes, it is said that people often do not read carefully...

        J Offline
        J Offline
        JonB
        wrote on 26 Oct 2021, 09:00 last edited by
        #28

        @jsulm
        It would be nice if questioners answered questions and acted on recommendations before just reposting that something does not work. Makes we wonder sometimes why we bother. If I ask a question and somebody gives some suggestions I act on those carefully before asking again. But that's another topic... :)

        1 Reply Last reply
        0
        • J JonB
          26 Oct 2021, 08:56

          @sonichy said in QString replace %U:

          @JonB deepin-draw "/home/sonichy/Desktop/KuGou.png"

          I previously wrote:

          Is sExec set to the correct full path to the executable? What do you think your process->setWorkingDirectory(path); achieves? Because if you think it is used to locate the executable to run, it is not.

          S Offline
          S Offline
          sonichy
          wrote on 26 Oct 2021, 09:08 last edited by sonichy
          #29

          @JonB
          The Linux desktop file installed by root(deb) do not contain Path.
          And absolute exe path do not work either:

          /usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
          

          Error handle

          connect(action, &QAction::triggered, [=](){
              QProcess *process = new QProcess;
              //process->setWorkingDirectory(path);
              qDebug() << sExec;
              //process->start(sExec); //crash
              process->setProgram(sExec);
              connect(process, &QProcess::readyReadStandardError, [=](){
                   qDebug() << process->errorString(); //nothing
              });
              bool b = process->startDetached();
              qDebug() << b; //false
              //QProcess::startDetached(sExec, QStringList(), path);
          });
          
          J J 2 Replies Last reply 26 Oct 2021, 09:19
          0
          • S sonichy
            26 Oct 2021, 09:08

            @JonB
            The Linux desktop file installed by root(deb) do not contain Path.
            And absolute exe path do not work either:

            /usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
            

            Error handle

            connect(action, &QAction::triggered, [=](){
                QProcess *process = new QProcess;
                //process->setWorkingDirectory(path);
                qDebug() << sExec;
                //process->start(sExec); //crash
                process->setProgram(sExec);
                connect(process, &QProcess::readyReadStandardError, [=](){
                     qDebug() << process->errorString(); //nothing
                });
                bool b = process->startDetached();
                qDebug() << b; //false
                //QProcess::startDetached(sExec, QStringList(), path);
            });
            
            J Offline
            J Offline
            JonB
            wrote on 26 Oct 2021, 09:19 last edited by JonB
            #30

            @sonichy

            • If you mean that qDebug() << sExec; outputs /usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\" then that is your problem. That line is not a program/executable, is it? The first word is the executable and the second word is an argument (and when passed as an argument it should not then have "s around it). And if that is the case it would have saved a lot of time if you had shown this from the start.

            • qDebug() << process->errorString(); //nothing This is not what you are supposed to output if you receive some data on standard error, you are supposed to print the data you receive.

            S 1 Reply Last reply 26 Oct 2021, 09:32
            0
            • S sonichy
              26 Oct 2021, 09:08

              @JonB
              The Linux desktop file installed by root(deb) do not contain Path.
              And absolute exe path do not work either:

              /usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
              

              Error handle

              connect(action, &QAction::triggered, [=](){
                  QProcess *process = new QProcess;
                  //process->setWorkingDirectory(path);
                  qDebug() << sExec;
                  //process->start(sExec); //crash
                  process->setProgram(sExec);
                  connect(process, &QProcess::readyReadStandardError, [=](){
                       qDebug() << process->errorString(); //nothing
                  });
                  bool b = process->startDetached();
                  qDebug() << b; //false
                  //QProcess::startDetached(sExec, QStringList(), path);
              });
              
              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 26 Oct 2021, 09:22 last edited by
              #31

              @sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
              "/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
              So, what do you want to start actually?!

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              J S 3 Replies Last reply 26 Oct 2021, 09:23
              1
              • J jsulm
                26 Oct 2021, 09:22

                @sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
                "/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
                So, what do you want to start actually?!

                J Offline
                J Offline
                JonB
                wrote on 26 Oct 2021, 09:23 last edited by
                #32

                @jsulm Who knows....

                1 Reply Last reply
                0
                • J jsulm
                  26 Oct 2021, 09:22

                  @sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
                  "/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
                  So, what do you want to start actually?!

                  S Offline
                  S Offline
                  sonichy
                  wrote on 26 Oct 2021, 09:24 last edited by
                  #33
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • J jsulm
                    26 Oct 2021, 09:22

                    @sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
                    "/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
                    So, what do you want to start actually?!

                    S Offline
                    S Offline
                    sonichy
                    wrote on 26 Oct 2021, 09:25 last edited by
                    #34

                    @jsulm said in QString replace %U:

                    @sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
                    "/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
                    So, what do you want to start actually?!

                    deepin-draw is relative path.
                    google-chrome is absolute path.
                    I make openwith function, I can choose program to start.

                    J 1 Reply Last reply 26 Oct 2021, 09:27
                    0
                    • S sonichy
                      26 Oct 2021, 09:25

                      @jsulm said in QString replace %U:

                      @sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
                      "/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
                      So, what do you want to start actually?!

                      deepin-draw is relative path.
                      google-chrome is absolute path.
                      I make openwith function, I can choose program to start.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 26 Oct 2021, 09:27 last edited by jsulm
                      #35

                      @sonichy Third time: add error handling to see why QProcess fails to start the executable...
                      Also, sExec should NOT contain executable and parameter! Parameters to the executable are passed as another QStringList parameter https://doc.qt.io/qt-5/qprocess.html#setArguments

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      S 1 Reply Last reply 26 Oct 2021, 09:28
                      0
                      • J jsulm
                        26 Oct 2021, 09:27

                        @sonichy Third time: add error handling to see why QProcess fails to start the executable...
                        Also, sExec should NOT contain executable and parameter! Parameters to the executable are passed as another QStringList parameter https://doc.qt.io/qt-5/qprocess.html#setArguments

                        S Offline
                        S Offline
                        sonichy
                        wrote on 26 Oct 2021, 09:28 last edited by
                        #36

                        @jsulm said in QString replace %U:

                        @sonichy Third time: add error handling to see why QProcess fails to start the executable...

                        Already add.

                        connect(process, &QProcess::readyReadStandardError, [=](){
                                 qDebug() << process->errorString(); //nothing
                        });
                        
                        J J 2 Replies Last reply 26 Oct 2021, 09:31
                        0
                        • S sonichy
                          26 Oct 2021, 09:28

                          @jsulm said in QString replace %U:

                          @sonichy Third time: add error handling to see why QProcess fails to start the executable...

                          Already add.

                          connect(process, &QProcess::readyReadStandardError, [=](){
                                   qDebug() << process->errorString(); //nothing
                          });
                          
                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 26 Oct 2021, 09:31 last edited by
                          #37

                          @sonichy said in QString replace %U:

                          Already add.

                          No.
                          You again did not read what I wrote: "I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred".
                          I'm out of this thread...

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • J JonB
                            26 Oct 2021, 09:19

                            @sonichy

                            • If you mean that qDebug() << sExec; outputs /usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\" then that is your problem. That line is not a program/executable, is it? The first word is the executable and the second word is an argument (and when passed as an argument it should not then have "s around it). And if that is the case it would have saved a lot of time if you had shown this from the start.

                            • qDebug() << process->errorString(); //nothing This is not what you are supposed to output if you receive some data on standard error, you are supposed to print the data you receive.

                            S Offline
                            S Offline
                            sonichy
                            wrote on 26 Oct 2021, 09:32 last edited by
                            #38

                            @JonB said in QString replace %U:

                            @sonichy

                            • If you mean that qDebug() << sExec; outputs /usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\" then that is your problem. That line is not a program/executable, is it? The first word is the executable and the second word is an argument (and when passed as an argument it should not then have "s around it). And if that is the case it would have saved a lot of time if you had shown this from the start.

                            • qDebug() << process->errorString(); //nothing This is not what you are supposed to output if you receive some data on standard error, you are supposed to print the data you receive.

                            /usr/bin/google-chrome-stable home/sonichy/Desktop/description.xml
                            false

                            Add "*" is to include space in filename.

                            1 Reply Last reply
                            0
                            • S sonichy
                              26 Oct 2021, 09:28

                              @jsulm said in QString replace %U:

                              @sonichy Third time: add error handling to see why QProcess fails to start the executable...

                              Already add.

                              connect(process, &QProcess::readyReadStandardError, [=](){
                                       qDebug() << process->errorString(); //nothing
                              });
                              
                              J Offline
                              J Offline
                              JonB
                              wrote on 26 Oct 2021, 09:34 last edited by JonB
                              #39

                              @sonichy
                              In my previous post:

                              • I already told you what you need to do in QProcess::readyReadStandardError, you have not acted on it.

                              • I already told you that if sExec is /usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\" (or anything similar, with or without the quotes) that won't work, why it won't work, and what you need to do about it. But you did not answer (and now you have but not acted on what I said). And nor will plain deepin-draw, unless it is on your PATH

                              I too am done.

                              S 1 Reply Last reply 26 Oct 2021, 10:22
                              0
                              • J JonB
                                26 Oct 2021, 09:34

                                @sonichy
                                In my previous post:

                                • I already told you what you need to do in QProcess::readyReadStandardError, you have not acted on it.

                                • I already told you that if sExec is /usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\" (or anything similar, with or without the quotes) that won't work, why it won't work, and what you need to do about it. But you did not answer (and now you have but not acted on what I said). And nor will plain deepin-draw, unless it is on your PATH

                                I too am done.

                                S Offline
                                S Offline
                                sonichy
                                wrote on 26 Oct 2021, 10:22 last edited by sonichy
                                #40

                                @JonB @jsulm

                                I found the reason: QProcess->setProgram(sExec), sExec can not contain space, if not will fail to start.
                                Program and arguments must separated!

                                sExec = sExec.left(sExec.indexOf(" "));
                                connect(action, &QAction::triggered, [=](){
                                    QProcess *process = new QProcess;
                                    process->setWorkingDirectory(path);
                                    qDebug() << sExec;
                                    process->setProgram(sExec);
                                    process->setArguments(QStringList() << filepath);
                                    bool b = process->startDetached();
                                    qDebug() << b;
                                });
                                
                                J 1 Reply Last reply 26 Oct 2021, 10:39
                                0
                                • S sonichy
                                  26 Oct 2021, 10:22

                                  @JonB @jsulm

                                  I found the reason: QProcess->setProgram(sExec), sExec can not contain space, if not will fail to start.
                                  Program and arguments must separated!

                                  sExec = sExec.left(sExec.indexOf(" "));
                                  connect(action, &QAction::triggered, [=](){
                                      QProcess *process = new QProcess;
                                      process->setWorkingDirectory(path);
                                      qDebug() << sExec;
                                      process->setProgram(sExec);
                                      process->setArguments(QStringList() << filepath);
                                      bool b = process->startDetached();
                                      qDebug() << b;
                                  });
                                  
                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 26 Oct 2021, 10:39 last edited by JonB
                                  #41

                                  @sonichy said in QString replace %U:

                                  QProcess->setProgram(sExec), sExec can not contain space, if not will fail to start.

                                  Not true. Space in the path to or name of the executable is fine.

                                  Program and arguments must separated!

                                  Which is why I told you earlier

                                  That line is not a program/executable, is it? The first word is the executable and the second word is an argument

                                  And that is why I would like you to read what we write and act on it, not just do nothing about it.....

                                  Whole of your lambda body code with QProcess *process = new QProcess onward could be replaced with just one line:

                                  QProcess::startDetached(sExec, QStringList() << filepath, path);
                                  

                                  if you want to avoid the memory leak.

                                  1 Reply Last reply
                                  3

                                  35/41

                                  26 Oct 2021, 09:27

                                  • Login

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