Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. how can I join and run a program when starting application?
QtWS25 Last Chance

how can I join and run a program when starting application?

Scheduled Pinned Locked Moved Unsolved Language Bindings
11 Posts 4 Posters 1.5k 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.
  • N Offline
    N Offline
    Nathan Miguel
    wrote on last edited by
    #1

    I created a secondary application in python to grab system information and export it to a txt file

    0_1558931547585_155f6e6f-c68a-433e-a76d-d664a532002c-image.png

    I wanted to know how I can configure qt, when it starts, it picks up that file runs and then it picks up the txt file it produces on it

    0_1558931772045_a7694c78-f0be-4f53-8045-e94326d83e62-image.png

    OBS: I am using qt qml, and the program is in the root directory of the source code

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Use QProcess to run your python script.

      One thing you can do is give that script a parameter so you manage where the generated file goes from your main application and you can retrieve it's content.

      One other possibility is to give your python script the option of printing these information on the standard output and still using QProcess you can directly get that information back into your main application without the need to generate a file.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      N 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Use QProcess to run your python script.

        One thing you can do is give that script a parameter so you manage where the generated file goes from your main application and you can retrieve it's content.

        One other possibility is to give your python script the option of printing these information on the standard output and still using QProcess you can directly get that information back into your main application without the need to generate a file.

        N Offline
        N Offline
        Nathan Miguel
        wrote on last edited by
        #3

        @SGaist yes I already tried, but I do not have the whole command because it contains " | ", forcing me to create an external script

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you explain more precisely what you are trying to run ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          N 1 Reply Last reply
          1
          • SGaistS SGaist

            Can you explain more precisely what you are trying to run ?

            N Offline
            N Offline
            Nathan Miguel
            wrote on last edited by
            #5

            @SGaist I'm trying to run a file that takes the name of the cpu and gpu and the gpu corporation "NVIDIA OR AMD"

            But does not it have a way in which the program takes the root directory where it is automatically? because then I just need to speak the folder where the executable is

            JonBJ 1 Reply Last reply
            0
            • N Nathan Miguel

              @SGaist I'm trying to run a file that takes the name of the cpu and gpu and the gpu corporation "NVIDIA OR AMD"

              But does not it have a way in which the program takes the root directory where it is automatically? because then I just need to speak the folder where the executable is

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

              @Nathan-Miguel
              It's getting really unclear (to me at least) what you are asking now. Is it about specifying the path to an executable you want to run? Is it about passing arguments to it? What | does the command have in it? Why not at least tell us exactly what command you're trying to run?!

              If you have an external command you have written, you might prefer to just have it write whatever to its standard output rather than to a file which you have to create somewhere. You can then use https://doc.qt.io/qt-5/qprocess.html#readAllStandardOutput to read back the text and not have to have file creation & reading. And BTW creating dynamic/temporary files in the folder where an executable lives, if that is what you are proposing to do, is not a good idea.

              N 1 Reply Last reply
              0
              • JonBJ JonB

                @Nathan-Miguel
                It's getting really unclear (to me at least) what you are asking now. Is it about specifying the path to an executable you want to run? Is it about passing arguments to it? What | does the command have in it? Why not at least tell us exactly what command you're trying to run?!

                If you have an external command you have written, you might prefer to just have it write whatever to its standard output rather than to a file which you have to create somewhere. You can then use https://doc.qt.io/qt-5/qprocess.html#readAllStandardOutput to read back the text and not have to have file creation & reading. And BTW creating dynamic/temporary files in the folder where an executable lives, if that is what you are proposing to do, is not a good idea.

                N Offline
                N Offline
                Nathan Miguel
                wrote on last edited by Nathan Miguel
                #7

                @JonB I managed to make the program run, but the txt file is being created in the wrong place

                rootdir: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug\debug

                location where the file should exit: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug\debug\sysinfo

                location of file output: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug

                0_1559246135618_21f8d4b9-bbff-487c-a169-622953f26e95-image.png

                QString systeminfo::getsysHardware()
                {
                    QString rootDir = QCoreApplication::applicationDirPath();
                    QString appDirWindows = "/sysinfo/main.exe";
                    QString appDirLinux = "/sysinfo/main";
                    QString output;
                    QString sysName = getsysType();
                
                    QProcess process;
                
                    if (sysName == "WINDOWS") {
                        process.start(rootDir+appDirWindows);
                        process.waitForFinished();
                
                
                    }
                    else if (sysName == "LINUX") {
                
                    }
                
                    return rootDir;
                }
                
                JonBJ 1 Reply Last reply
                0
                • N Nathan Miguel

                  @JonB I managed to make the program run, but the txt file is being created in the wrong place

                  rootdir: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug\debug

                  location where the file should exit: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug\debug\sysinfo

                  location of file output: E:\Git\Denoiser-Script\QML_C++\build-Denosier-Desktop_Qt_5_12_3_MSVC2017_64bit2-Debug

                  0_1559246135618_21f8d4b9-bbff-487c-a169-622953f26e95-image.png

                  QString systeminfo::getsysHardware()
                  {
                      QString rootDir = QCoreApplication::applicationDirPath();
                      QString appDirWindows = "/sysinfo/main.exe";
                      QString appDirLinux = "/sysinfo/main";
                      QString output;
                      QString sysName = getsysType();
                  
                      QProcess process;
                  
                      if (sysName == "WINDOWS") {
                          process.start(rootDir+appDirWindows);
                          process.waitForFinished();
                  
                  
                      }
                      else if (sysName == "LINUX") {
                  
                      }
                  
                      return rootDir;
                  }
                  
                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Nathan-Miguel
                  But it is the process you run (main.exe) which creates this systeminfo.txt in some directory, is it not? Yet you are showing the code of your Qt application which runs the main.exe? Are you now talking about what the current directory will be for the main.exe you run from your Qt program (perhaps because it creates systeminfo.txt without specifying a path)?? I'm lost....

                  As I suggested before, this would still be simpler anyway if you chose not to do it via a temporary file somewhere in your executable's directory area. Which is waiting to bite you if & when you distribute your application. But as you please.

                  N 1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    zubair ahmed
                    Banned
                    wrote on last edited by zubair ahmed
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Nathan-Miguel
                      But it is the process you run (main.exe) which creates this systeminfo.txt in some directory, is it not? Yet you are showing the code of your Qt application which runs the main.exe? Are you now talking about what the current directory will be for the main.exe you run from your Qt program (perhaps because it creates systeminfo.txt without specifying a path)?? I'm lost....

                      As I suggested before, this would still be simpler anyway if you chose not to do it via a temporary file somewhere in your executable's directory area. Which is waiting to bite you if & when you distribute your application. But as you please.

                      N Offline
                      N Offline
                      Nathan Miguel
                      wrote on last edited by
                      #10

                      @JonB yes, but when the program executes it does not create the txt file in the same directory as main.exe is, making it impossible for me to get this txt

                      JonBJ 1 Reply Last reply
                      0
                      • N Nathan Miguel

                        @JonB yes, but when the program executes it does not create the txt file in the same directory as main.exe is, making it impossible for me to get this txt

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

                        @Nathan-Miguel

                        As I said/suspevted:

                        • You show us the code of your Qt application, which does not create the file, so it does not help.

                        • Nowhere do you you show whatever code does create the file, so since we cannot see that we cannot advise what it is you need to do.

                        • I wrote above:

                        Are you now talking about what the current directory will be for the main.exe you run from your Qt program (perhaps because it creates systeminfo.txt without specifying a path)??

                        but you didn't reply to that. If you want help, you'll need to provide information.

                        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