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. Starting a selfmade c++ application via Qprocess
Forum Updated to NodeBB v4.3 + New Features

Starting a selfmade c++ application via Qprocess

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 1.7k Views 2 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.
  • C Offline
    C Offline
    christophator
    wrote on last edited by christophator
    #1

    Hi,
    i have a QT widget app. wich starts a c++ application via QProcess.
    I wrote this on win10 and now i have to install it on linux/debian9.

    I changed the path in linux format. Compiled the c++ application on my debian system.
    But it won't start.
    Here is the code:

    Constructor:

    TemperaturMessung::TemperaturMessung(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::TemperaturMessung)
    {
        ui->setupUi(this);
        process = new QProcess(this);
        process->setProcessChannelMode(QProcess::MergedChannels);
        program = "./Dokumente/Tempmess/Sources/Comreader/Tempmess";  //Tempmess is the c++ aplication wich i want to start
        fileName = "/Dokumente/Tempmess/Messprotokolle";
        ui->speicherOrt->insert(fileName);
        connect( process, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()) );
        connect( process, SIGNAL(readyReadStandardError()), this, SLOT(processOutput()) );
        connect( process, SIGNAL(started()), ui->startButton, SLOT(hide()));
        connect( process, SIGNAL(finished(int,QProcess::ExitStatus)), ui->startButton, SLOT(show()));
    
    }
    

    Function which starts the process:

    void TemperaturMessung::on_startButton_clicked()
    {
       //bla bla...
    
        QStringList argv;
        argv << abtastStr << kanalStr << dauerStr<<fileName;
        process->start(program,argv);
        process->waitForStarted();
    }
    

    Is there anything i have to do with my self compiled programm (The Tempmess thing)?

    Thanks for help!

    K Pablo J. RoginaP JonBJ 3 Replies Last reply
    0
    • C christophator

      Hi,
      i have a QT widget app. wich starts a c++ application via QProcess.
      I wrote this on win10 and now i have to install it on linux/debian9.

      I changed the path in linux format. Compiled the c++ application on my debian system.
      But it won't start.
      Here is the code:

      Constructor:

      TemperaturMessung::TemperaturMessung(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::TemperaturMessung)
      {
          ui->setupUi(this);
          process = new QProcess(this);
          process->setProcessChannelMode(QProcess::MergedChannels);
          program = "./Dokumente/Tempmess/Sources/Comreader/Tempmess";  //Tempmess is the c++ aplication wich i want to start
          fileName = "/Dokumente/Tempmess/Messprotokolle";
          ui->speicherOrt->insert(fileName);
          connect( process, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()) );
          connect( process, SIGNAL(readyReadStandardError()), this, SLOT(processOutput()) );
          connect( process, SIGNAL(started()), ui->startButton, SLOT(hide()));
          connect( process, SIGNAL(finished(int,QProcess::ExitStatus)), ui->startButton, SLOT(show()));
      
      }
      

      Function which starts the process:

      void TemperaturMessung::on_startButton_clicked()
      {
         //bla bla...
      
          QStringList argv;
          argv << abtastStr << kanalStr << dauerStr<<fileName;
          process->start(program,argv);
          process->waitForStarted();
      }
      

      Is there anything i have to do with my self compiled programm (The Tempmess thing)?

      Thanks for help!

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @christophator

      Hi and welcome to devnet forum

      Looks like you got messed up with path issues.

          program = "./Dokumente/Tempmess/Sources/Comreader/Tempmess";  //Tempmess is the c++ aplication wich i want to start
          fileName = "/Dokumente/Tempmess/Messprotokolle";
      

      The program path is a relative path starting at your current working.
      The fileName path is an absolute path. It does not really look as a typical linux path.

      You can check the currentPath

      qDebug() << QDir::currentPath();
      

      From there you can check if the rest ist ok.

      Alternatively I would recommend starting with fixed complete absolute path' which typically helps to get an overview.
      Also you need to check that your C++ application is starting outside in a terminal.

      Vote the answer(s) that helped you to solve your issue(s)

      C 1 Reply Last reply
      7
      • C christophator

        Hi,
        i have a QT widget app. wich starts a c++ application via QProcess.
        I wrote this on win10 and now i have to install it on linux/debian9.

        I changed the path in linux format. Compiled the c++ application on my debian system.
        But it won't start.
        Here is the code:

        Constructor:

        TemperaturMessung::TemperaturMessung(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::TemperaturMessung)
        {
            ui->setupUi(this);
            process = new QProcess(this);
            process->setProcessChannelMode(QProcess::MergedChannels);
            program = "./Dokumente/Tempmess/Sources/Comreader/Tempmess";  //Tempmess is the c++ aplication wich i want to start
            fileName = "/Dokumente/Tempmess/Messprotokolle";
            ui->speicherOrt->insert(fileName);
            connect( process, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()) );
            connect( process, SIGNAL(readyReadStandardError()), this, SLOT(processOutput()) );
            connect( process, SIGNAL(started()), ui->startButton, SLOT(hide()));
            connect( process, SIGNAL(finished(int,QProcess::ExitStatus)), ui->startButton, SLOT(show()));
        
        }
        

        Function which starts the process:

        void TemperaturMessung::on_startButton_clicked()
        {
           //bla bla...
        
            QStringList argv;
            argv << abtastStr << kanalStr << dauerStr<<fileName;
            process->start(program,argv);
            process->waitForStarted();
        }
        

        Is there anything i have to do with my self compiled programm (The Tempmess thing)?

        Thanks for help!

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @christophator once you solve the issue with the *nix path, you may want to consider using some configuration file (i.e. via QSettings class) to store the path/arguments of the external C++ app to launch so to avoid recompiling your Qt application for Linux, WIndows, etc everytime the path/platform changes

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        6
        • C christophator

          Hi,
          i have a QT widget app. wich starts a c++ application via QProcess.
          I wrote this on win10 and now i have to install it on linux/debian9.

          I changed the path in linux format. Compiled the c++ application on my debian system.
          But it won't start.
          Here is the code:

          Constructor:

          TemperaturMessung::TemperaturMessung(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::TemperaturMessung)
          {
              ui->setupUi(this);
              process = new QProcess(this);
              process->setProcessChannelMode(QProcess::MergedChannels);
              program = "./Dokumente/Tempmess/Sources/Comreader/Tempmess";  //Tempmess is the c++ aplication wich i want to start
              fileName = "/Dokumente/Tempmess/Messprotokolle";
              ui->speicherOrt->insert(fileName);
              connect( process, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()) );
              connect( process, SIGNAL(readyReadStandardError()), this, SLOT(processOutput()) );
              connect( process, SIGNAL(started()), ui->startButton, SLOT(hide()));
              connect( process, SIGNAL(finished(int,QProcess::ExitStatus)), ui->startButton, SLOT(show()));
          
          }
          

          Function which starts the process:

          void TemperaturMessung::on_startButton_clicked()
          {
             //bla bla...
          
              QStringList argv;
              argv << abtastStr << kanalStr << dauerStr<<fileName;
              process->start(program,argv);
              process->waitForStarted();
          }
          

          Is there anything i have to do with my self compiled programm (The Tempmess thing)?

          Thanks for help!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @christophator
          You should discover why it "did not start" under Linux if you add signal/slot for http://doc.qt.io/qt-5/qprocess.html#errorOccurred. You have done well hooking up the other signals, but you really need that one too, especially for production.

          1 Reply Last reply
          4
          • K koahnig

            @christophator

            Hi and welcome to devnet forum

            Looks like you got messed up with path issues.

                program = "./Dokumente/Tempmess/Sources/Comreader/Tempmess";  //Tempmess is the c++ aplication wich i want to start
                fileName = "/Dokumente/Tempmess/Messprotokolle";
            

            The program path is a relative path starting at your current working.
            The fileName path is an absolute path. It does not really look as a typical linux path.

            You can check the currentPath

            qDebug() << QDir::currentPath();
            

            From there you can check if the rest ist ok.

            Alternatively I would recommend starting with fixed complete absolute path' which typically helps to get an overview.
            Also you need to check that your C++ application is starting outside in a terminal.

            C Offline
            C Offline
            christophator
            wrote on last edited by
            #5

            @koahnig and @Pablo-J-Rogina thank you very much!

            I didn't understand how the linux paths work.

            I put my c++ application into the current folder of the Qt program and called only the name in the program path.
            There it works :)
            Now I will get into the QDir and QSettings class to solv it properly.

            JonBJ 1 Reply Last reply
            0
            • C christophator

              @koahnig and @Pablo-J-Rogina thank you very much!

              I didn't understand how the linux paths work.

              I put my c++ application into the current folder of the Qt program and called only the name in the program path.
              There it works :)
              Now I will get into the QDir and QSettings class to solv it properly.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @christophator
              Linux paths work more-or-less identically to Windows ones, just they use / instead of \ and don't have a crazy drive letter.

              C K 2 Replies Last reply
              0
              • JonBJ JonB

                @christophator
                Linux paths work more-or-less identically to Windows ones, just they use / instead of \ and don't have a crazy drive letter.

                C Offline
                C Offline
                christophator
                wrote on last edited by
                #7

                @JonB
                Yeah :D and I didn't realized that I used a ralative path wich starts at the current folder..
                Now I got it!

                JonBJ 1 Reply Last reply
                1
                • C christophator

                  @JonB
                  Yeah :D and I didn't realized that I used a ralative path wich starts at the current folder..
                  Now I got it!

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @christophator
                  Any path which does not start (very first character) with a / (Linux) or \ (Windows) is relative. And under Windows be careful with drive letters: D:\fred is absolute but D:fred is actually relative, to the current directory on drive D:, whatever that is.

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @christophator
                    Linux paths work more-or-less identically to Windows ones, just they use / instead of \ and don't have a crazy drive letter.

                    K Offline
                    K Offline
                    koahnig
                    wrote on last edited by
                    #9

                    @JonB said in Starting a selfmade c++ application via Qprocess:

                    @christophator
                    Linux paths work more-or-less identically to Windows ones, just they use / instead of \ and don't have a crazy drive letter.

                    Not exactly. That seem to reflect the blinker view of linux guys.

                    Windows does tolerate '/' for a long time already. Me, as a Windows boy, I simply switched to the forward slash long ago.

                    When you are not using linux for daily work, you ask yourself a lot where you can find that stupid device again.

                    Vote the answer(s) that helped you to solve your issue(s)

                    JonBJ 1 Reply Last reply
                    0
                    • K koahnig

                      @JonB said in Starting a selfmade c++ application via Qprocess:

                      @christophator
                      Linux paths work more-or-less identically to Windows ones, just they use / instead of \ and don't have a crazy drive letter.

                      Not exactly. That seem to reflect the blinker view of linux guys.

                      Windows does tolerate '/' for a long time already. Me, as a Windows boy, I simply switched to the forward slash long ago.

                      When you are not using linux for daily work, you ask yourself a lot where you can find that stupid device again.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @koahnig
                      Since you have chosen to question what I wrote (as a simplified answer), I shall return the favour by saying "Not exactly" to you!

                      Not exactly. That seem to reflect the blinker view of linux guys.
                      Windows does tolerate '/' for a long time already. Me, as a Windows boy, I simply switched to the forward slash long ago.

                      Nope. That's too simplistic, which is why I didn't mention it! Try each of the following:

                      dir \c
                      dir /c
                      

                      They don't produce the same, do they? So it's not fair to say that Windows users can use / instead of \, is it? That seem to reflect the blinker view of Windows guys. :) This is only one example.....

                      K 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @koahnig
                        Since you have chosen to question what I wrote (as a simplified answer), I shall return the favour by saying "Not exactly" to you!

                        Not exactly. That seem to reflect the blinker view of linux guys.
                        Windows does tolerate '/' for a long time already. Me, as a Windows boy, I simply switched to the forward slash long ago.

                        Nope. That's too simplistic, which is why I didn't mention it! Try each of the following:

                        dir \c
                        dir /c
                        

                        They don't produce the same, do they? So it's not fair to say that Windows users can use / instead of \, is it? That seem to reflect the blinker view of Windows guys. :) This is only one example.....

                        K Offline
                        K Offline
                        koahnig
                        wrote on last edited by
                        #11

                        @JonB said in Starting a selfmade c++ application via Qprocess:

                        @koahnig
                        Since you have chosen to question what I wrote (as a simplified answer), I shall return the favour by saying "Not exactly" to you!

                        Not exactly. That seem to reflect the blinker view of linux guys.
                        Windows does tolerate '/' for a long time already. Me, as a Windows boy, I simply switched to the forward slash long ago.

                        Nope. That's too simplistic, which is why I didn't mention it! Try each of the following:

                        dir \c
                        dir /c
                        

                        They don't produce the same, do they? So it's not fair to say that Windows users can use / instead of \, is it? That seem to reflect the blinker view of Windows guys. :) This is only one example.....

                        :D
                        Not sure, if it is the blinker view of Windows guy or of someone concentrating on a specific topic, the path issue, without mentioning it explicitly. ;) Also, if I am not mistaken, is the backslash used mainly for separation in a long path.

                        BTW Have fun to use in Windows

                        dir \c
                        

                        which will not work. Also there the recommendation to use better a forward slash will help. ;)

                        Anyway I am not interested in specific linux nor windows bashing. Especially the backslash within a path and its special meaning within string drives probably most of the developers nuts. Therefore I am gladly using the forward slash whenever possible.

                        Vote the answer(s) that helped you to solve your issue(s)

                        JonBJ 1 Reply Last reply
                        0
                        • K koahnig

                          @JonB said in Starting a selfmade c++ application via Qprocess:

                          @koahnig
                          Since you have chosen to question what I wrote (as a simplified answer), I shall return the favour by saying "Not exactly" to you!

                          Not exactly. That seem to reflect the blinker view of linux guys.
                          Windows does tolerate '/' for a long time already. Me, as a Windows boy, I simply switched to the forward slash long ago.

                          Nope. That's too simplistic, which is why I didn't mention it! Try each of the following:

                          dir \c
                          dir /c
                          

                          They don't produce the same, do they? So it's not fair to say that Windows users can use / instead of \, is it? That seem to reflect the blinker view of Windows guys. :) This is only one example.....

                          :D
                          Not sure, if it is the blinker view of Windows guy or of someone concentrating on a specific topic, the path issue, without mentioning it explicitly. ;) Also, if I am not mistaken, is the backslash used mainly for separation in a long path.

                          BTW Have fun to use in Windows

                          dir \c
                          

                          which will not work. Also there the recommendation to use better a forward slash will help. ;)

                          Anyway I am not interested in specific linux nor windows bashing. Especially the backslash within a path and its special meaning within string drives probably most of the developers nuts. Therefore I am gladly using the forward slash whenever possible.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #12

                          @koahnig

                          BTW Have fun to use in Windows
                          dir \c
                          which will not work.

                          ? Of course it "works". dir \c means "list the file/directory named c in the root folder of the current drive". (If there isn't one, of course it reports File not found, but it's still "working".) OTOH, dir /c means "list all the files in the current directory on the current drive, passing the /c switch to dir". Quite different. Which is why I would never use or recommend / instead of \ for paths in Windows, and I'm surprised you get away with it in practice..... Not Linux vs Windows "bashing" (it was you who used the word "blinker"!), just a heads-up as to it's not robust enough to risk IMHO.....

                          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