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 create a process in C++ or Qt?
Forum Updated to NodeBB v4.3 + New Features

How can I create a process in C++ or Qt?

Scheduled Pinned Locked Moved Unsolved Language Bindings
9 Posts 5 Posters 4.2k 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.
  • L Offline
    L Offline
    logancale2015
    wrote on last edited by
    #1

    hello people a need your help, can be with qt or c++, i want to create a process BUT a process that use a function of my program not an external program, something like this .... sorry for the example and forgive my english thanks

    void count(){
    bbla
    bla
    bla
    }

    int main(){
    QProcess p = new QProcess(count());
    p.start();
    }

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

      Hi
      When you select New Project, you can select Qt Console Application.
      THen you get a non gui app.
      You will have to read the parameters in your app and respond to them.

      also
      QProcess(count());

      is never going to happen. Syntax is not valid.

      you must use the normal way of passing parameters.

      like

      QStringList arguments;
      arguments << "-style" << "motif";
       
      QProcess *myProcess = new QProcess(this);
      myProcess->start(program, arguments);
      
      1 Reply Last reply
      0
      • L Offline
        L Offline
        logancale2015
        wrote on last edited by
        #3

        yes i know about the sintax that was an example to ilustrate it

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

          I think what you want is a thread, not a process.

          #include <iostream>
          #include <thread>
          void count(){
          for(int i=0;i<100;++i)
          std::cout << i;
          }
          int main(){
          std::thread countThread(count);
          // do other stuff
          countThread.join();
          return 0;
          }
          

          "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

          L 1 Reply Last reply
          0
          • VRoninV VRonin

            I think what you want is a thread, not a process.

            #include <iostream>
            #include <thread>
            void count(){
            for(int i=0;i<100;++i)
            std::cout << i;
            }
            int main(){
            std::thread countThread(count);
            // do other stuff
            countThread.join();
            return 0;
            }
            
            L Offline
            L Offline
            logancale2015
            wrote on last edited by
            #5

            @VRonin no no a thread the think is that when i close the main app the thread is going to close to and i dont want this

            J.HilkJ 1 Reply Last reply
            0
            • L logancale2015

              @VRonin no no a thread the think is that when i close the main app the thread is going to close to and i dont want this

              J.HilkJ Online
              J.HilkJ Online
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @logancale2015

              in your main.cpp

              QApplication qApp;
              qApp.setQuitOnLastWindowClosed(false);
              

              and your app wont terminate when you close the window.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              L 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @logancale2015

                in your main.cpp

                QApplication qApp;
                qApp.setQuitOnLastWindowClosed(false);
                

                and your app wont terminate when you close the window.

                L Offline
                L Offline
                logancale2015
                wrote on last edited by
                #7

                @J.Hilk is a console app

                mrjjM 1 Reply Last reply
                0
                • L logancale2015

                  @J.Hilk is a console app

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @logancale2015
                  Hi
                  if Qt console app then it will run until quit() is called.
                  int main(int argc, char *argv[])
                  {
                  QCoreApplication a(argc, argv);
                  return a.exec(); // stays here
                  }

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

                    Hi,

                    This looks like it could be a job for QtConcurrent::run.

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

                    1 Reply Last reply
                    3

                    • Login

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