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. Converting C# code to Qt code of Process Functions
Forum Updated to NodeBB v4.3 + New Features

Converting C# code to Qt code of Process Functions

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 1.9k 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.
  • Prince_0912P Offline
    Prince_0912P Offline
    Prince_0912
    wrote on last edited by Prince_0912
    #1

    Hello i stuck in these code,
    How can i convert these code snippet to equivalent Qt code. i didn't find exact solution of it.

    System.Diagnostics.Process p = new System.Diagnostics.Process();

    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

    p.StartInfo.FileName = secPath;

    p.StartInfo.Arguments = appName + " " + appKey + " " + ukKey + " " + removeKey.ToString();

    p.StartInfo.Verb = p.StartInfo.Verbs[1];

    p.StartInfo.UseShellExecute = true;

    bool b= p.Start();

    Thanks in advance.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      http://doc.qt.io/qt-5/qprocess.html#details

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • Prince_0912P Offline
        Prince_0912P Offline
        Prince_0912
        wrote on last edited by
        #3

        @VRonin
        I already refer this link but it not exactly working as i mentioned in code.i want to convert those few line in Qt C++ code.

        aha_1980A 1 Reply Last reply
        0
        • Prince_0912P Prince_0912

          @VRonin
          I already refer this link but it not exactly working as i mentioned in code.i want to convert those few line in Qt C++ code.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by aha_1980
          #4

          @Prince_0912 said in Converting C# code to Qt code:

          I already refer this link but it not exactly working as i mentioned in code.

          What is not working?

          i want to convert those few line in Qt C++ code.

          Yeah, you already told us.

          In principle, when porting from one language to another, it's most important to understand what the original code does, and then find a solution in the other language. So please tell us, what do you really want to achive?

          Example: "I want to run an external program in a command line window" or "I want to run an external program and capture all output of this program"

          Qt has to stay free or it will die.

          1 Reply Last reply
          4
          • Prince_0912P Offline
            Prince_0912P Offline
            Prince_0912
            wrote on last edited by VRonin
            #5

            Thanks @aha_1980 ,

            1. sets the verb to use when opening the application or document specified by the Filename to the process object
            2. sets the window state to use when the process is started.
            3. sets the set of command-line arguments to use when starting the application.
            4. sets the verb to use when opening the application or document specified by the FileName.
            5. sets a value indicating whether to use the operating system shell to start the process.

            here i"m stuck for doing these activities.

            aha_1980A 1 Reply Last reply
            0
            • Prince_0912P Prince_0912

              Thanks @aha_1980 ,

              1. sets the verb to use when opening the application or document specified by the Filename to the process object
              2. sets the window state to use when the process is started.
              3. sets the set of command-line arguments to use when starting the application.
              4. sets the verb to use when opening the application or document specified by the FileName.
              5. sets a value indicating whether to use the operating system shell to start the process.

              here i"m stuck for doing these activities.

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Prince_0912

              I'm not sure if QProcess can handle all these requirements, as it's a cross-platform abstraction, in contrast to C# which is (mainly) build upon the Windows API.

              If your program is Windows-only, you could use the Win32-API directly, keyword CreateProcess.

              One thing that's unclear for me, what is a verb?

              And last but not least, you explained the original code, but what's really important is: what does this code do?

              Qt has to stay free or it will die.

              1 Reply Last reply
              1
              • Prince_0912P Offline
                Prince_0912P Offline
                Prince_0912
                wrote on last edited by
                #7

                verbs are "Edit", "Open", "OpenAsReadOnly", "Print", and "Printto".
                These code is staring .exe and just before this console application appear it passes the arguments to .exe.

                aha_1980A 1 Reply Last reply
                0
                • Prince_0912P Prince_0912

                  verbs are "Edit", "Open", "OpenAsReadOnly", "Print", and "Printto".
                  These code is staring .exe and just before this console application appear it passes the arguments to .exe.

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Prince_0912

                  These code is staring .exe and just before this console application appear it passes the arguments to .exe.

                  Ok, your description sounds as QProcess::startDetached could help.

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  1
                  • Prince_0912P Offline
                    Prince_0912P Offline
                    Prince_0912
                    wrote on last edited by
                    #9

                    @aha_1980 yeah,
                    i put it by

                    QProcess p = new QProcess(this);

                    QStringList pList = appName + " " + appKey + " " + ukKey + " " + static_cast<QString>(removeKey);

                    p.start(secPath, pList, QIODevice::ReadWrite);

                    VRoninV 1 Reply Last reply
                    0
                    • Prince_0912P Prince_0912

                      @aha_1980 yeah,
                      i put it by

                      QProcess p = new QProcess(this);

                      QStringList pList = appName + " " + appKey + " " + ukKey + " " + static_cast<QString>(removeKey);

                      p.start(secPath, pList, QIODevice::ReadWrite);

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by VRonin
                      #10

                      @Prince_0912 said in Converting C# code to Qt code of Process Functions:

                      QProcess p = new QProcess(this);
                      QStringList pList = appName + " " + appKey + " " + ukKey + " " + static_cast<QString>(removeKey);
                      p.start(secPath, pList, QIODevice::ReadWrite);

                      Wouldn't it be?

                      QProcess p = new QProcess(this);
                      QStringList  pList { {appKey , ukKey,removeKey}};
                       p.start(secPath+ '/' +appName , pList, QIODevice::ReadWrite);
                      

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      3
                      • Prince_0912P Offline
                        Prince_0912P Offline
                        Prince_0912
                        wrote on last edited by
                        #11

                        Thanks @VRonin @aha_1980 for giving solution flow. Now i can do it by my self.

                        1 Reply Last reply
                        1

                        • Login

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