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

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.
  • J JonB
    26 Oct 2021, 08:00

    @sonichy said in QString replace %U:

    Yes , the process do not start !

    Under what circumstances? The way your code above is/was? After you have changed to make QProcess a stack variable? Both?

    Please try to give some clear detail with your posts. You give so little information, we have to keep asking you for more....

    S Offline
    S Offline
    sonichy
    wrote on 26 Oct 2021, 08:07 last edited by
    #16

    @JonB This is new problem after modify the code, QProcess do not start in lambda !

    J J 2 Replies Last reply 26 Oct 2021, 08:09
    0
    • S sonichy
      26 Oct 2021, 08:07

      @JonB This is new problem after modify the code, QProcess do not start in lambda !

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

      @sonichy Would you mind to post the current code, or should we guess what is wrong?

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

      S 1 Reply Last reply 26 Oct 2021, 08:24
      0
      • S sonichy
        26 Oct 2021, 08:07

        @JonB This is new problem after modify the code, QProcess do not start in lambda !

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

        @sonichy said in QString replace %U:

        This is new problem after modify the code

        Fair enough, I did say you would have see whether it causes problems. This raises a nasty question of what Qt requires the scope/lifetime of the process used in QProcess::startDetached() to be: it cannot be "forever", because we know detached processes survive even exiting the parent program. Maybe it requires it to exist till at least started() signal has been received, I don't know.

        Actually, hang on! The overload of startDetached you are using is bool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr). That is static!

        Soooo:

        • process->setWorkingDirectory(sPath); has no effect (the method signature above takes an optional parameter for the working directory instead).

        • Your QProcess *process = new QProcess; is not used.

        • You can write QProcess::startDetached(sExec, QStringList()); instead, no QProcess instance needed, and no leaking.

        • Given this I find it hard to believe that changing QProcess *process to QProcess process can have any effect....

        S 1 Reply Last reply 26 Oct 2021, 08:33
        0
        • J jsulm
          26 Oct 2021, 08:09

          @sonichy Would you mind to post the current code, or should we guess what is wrong?

          S Offline
          S Offline
          sonichy
          wrote on 26 Oct 2021, 08:24 last edited by
          #19

          @jsulm Click QAction QProcess do not start, copy qDebug() content to terminal can run.

          QString sExec = readSettings(desktop, "Desktop Entry", "Exec");
          sExec.replace(QString("%U"), filepath, Qt::CaseInsensitive);
          sExec.replace(QString("%F"), filepath, Qt::CaseInsensitive);
          connect(action, &QAction::triggered, [=](){
                 QProcess *process = new QProcess;
                 process->setWorkingDirectory(path);
                 qDebug() << sExec;
                 //process->start(sExec);
                 process->setProgram(sExec);
                 process->startDetached();
          });
          
          J 1 Reply Last reply 26 Oct 2021, 08:32
          0
          • S sonichy
            26 Oct 2021, 08:24

            @jsulm Click QAction QProcess do not start, copy qDebug() content to terminal can run.

            QString sExec = readSettings(desktop, "Desktop Entry", "Exec");
            sExec.replace(QString("%U"), filepath, Qt::CaseInsensitive);
            sExec.replace(QString("%F"), filepath, Qt::CaseInsensitive);
            connect(action, &QAction::triggered, [=](){
                   QProcess *process = new QProcess;
                   process->setWorkingDirectory(path);
                   qDebug() << sExec;
                   //process->start(sExec);
                   process->setProgram(sExec);
                   process->startDetached();
            });
            
            J Offline
            J Offline
            JonB
            wrote on 26 Oct 2021, 08:32 last edited by JonB
            #20

            @sonichy
            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.

            The bool QProcess::startDetached(qint64 *pid = nullptr) overload you are now using has a return value. Do you think you ought look at that if you are having a problem?

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

              @sonichy said in QString replace %U:

              This is new problem after modify the code

              Fair enough, I did say you would have see whether it causes problems. This raises a nasty question of what Qt requires the scope/lifetime of the process used in QProcess::startDetached() to be: it cannot be "forever", because we know detached processes survive even exiting the parent program. Maybe it requires it to exist till at least started() signal has been received, I don't know.

              Actually, hang on! The overload of startDetached you are using is bool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr). That is static!

              Soooo:

              • process->setWorkingDirectory(sPath); has no effect (the method signature above takes an optional parameter for the working directory instead).

              • Your QProcess *process = new QProcess; is not used.

              • You can write QProcess::startDetached(sExec, QStringList()); instead, no QProcess instance needed, and no leaking.

              • Given this I find it hard to believe that changing QProcess *process to QProcess process can have any effect....

              S Offline
              S Offline
              sonichy
              wrote on 26 Oct 2021, 08:33 last edited by
              #21

              @JonB Two method:
              bool QProcess::startDetached(qint64 *pid = nullptr)

              [static] bool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr)

              And static do not start either.

              QProcess::startDetached(sExec, QStringList(), path);
              
              J J 2 Replies Last reply 26 Oct 2021, 08:34
              0
              • S sonichy
                26 Oct 2021, 08:33

                @JonB Two method:
                bool QProcess::startDetached(qint64 *pid = nullptr)

                [static] bool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr)

                And static do not start either.

                QProcess::startDetached(sExec, QStringList(), path);
                
                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 26 Oct 2021, 08:34 last edited by
                #22

                @sonichy Please add error handling - QProcess has functionality for that...

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

                1 Reply Last reply
                1
                • S sonichy
                  26 Oct 2021, 08:33

                  @JonB Two method:
                  bool QProcess::startDetached(qint64 *pid = nullptr)

                  [static] bool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr)

                  And static do not start either.

                  QProcess::startDetached(sExec, QStringList(), path);
                  
                  J Offline
                  J Offline
                  JonB
                  wrote on 26 Oct 2021, 08:35 last edited by
                  #23

                  @sonichy
                  Then I do not see that anything you have had so far can have succeeded, but it's most unclear from your comments what that case is.

                  As per my previous, could you please show what your qDebug() << sExec; is outputting, instead of making us guess?

                  S 1 Reply Last reply 26 Oct 2021, 08:46
                  0
                  • J JonB
                    26 Oct 2021, 08:35

                    @sonichy
                    Then I do not see that anything you have had so far can have succeeded, but it's most unclear from your comments what that case is.

                    As per my previous, could you please show what your qDebug() << sExec; is outputting, instead of making us guess?

                    S Offline
                    S Offline
                    sonichy
                    wrote on 26 Oct 2021, 08:46 last edited by
                    #24

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

                    J J 2 Replies Last reply 26 Oct 2021, 08:49
                    0
                    • S sonichy
                      26 Oct 2021, 08:46

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

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

                      @sonichy said in QString replace %U:

                      deepin-draw

                      This is a relative path. Pass whole path, so it can actually be found...
                      And please add error handling...

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

                      1 Reply Last reply
                      1
                      • 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

                                          25/41

                                          26 Oct 2021, 08:49

                                          • Login

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