Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Converting C# code to Qt code of Process Functions



  • 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.





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


  • Lifetime Qt Champion

    @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"



  • 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.


  • Lifetime Qt Champion

    @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?



  • 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.


  • Lifetime Qt Champion

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



  • @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);



  • @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);
    


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


Log in to reply