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. Using QProcess[solved]
Forum Updated to NodeBB v4.3 + New Features

Using QProcess[solved]

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.0k 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.
  • K Offline
    K Offline
    kitten
    wrote on last edited by
    #1

    hi to everyone
    i want to run an application in my program so i use qprocess,and i use this code:
    @ QString program = "calc.exe"
    QProcess process(this);
    process.start(program);
    connect( &process, SIGNAL(error(QProcess::ProcessError)),this,SLOT(processError(QProcess::ProcessError)));
    @
    and so i will receive its errors,it will apear for one second and after that it crashed and the error say it is crashed
    i want to know why?and am i write this program correctly?

    www.kitten.mihanblog.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      You're creating your QProcess on the stack, but you're giving it a parent. That's a bad thing that you must not do.

      Try this:
      @
      QString program = "calc.exe";
      QProcess *process = new QProcess(this); // On the heap, not the stack.

      // Also, connect your signals and slots /before/ you start your process.
      // You can also eliminate the "this", and use the 3-parameter version of
      // connect() which assumes "this" as the owner of the slot.
      connect(process, SIGNAL(error(QProcess:ProcessError)),
      SLOT(processError(QProcess::ProcessError)));

      process->start(); // Then start your process once everything is all set up.
      @

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hi,
        I've done some QProcess stuff myself, but to know why your program crashed is not so easy I think. The QProcess just keeps track of your "client" program. The "client" program itself will run on the OS. It isn't set within the HEAP of your Qt program! The QProcess just get's the information back from the OS about that "client" process you started. What mLong said is in dead a big improvement. First connect your signals, then start the process. The process might even crash when the start command is entered.
        The value you get from the client when it crashed has probably to do with OS values. The same as old DOS programs always exiting with 1 when all went ok.
        Btw, when you kill your own program and do not use the process->close() the "client" program will keep on running.
        If you really want to know why the client crashed, you may need to look into your OS. For example I needed to control the Window in which the client was started, but I needed Windows API calls to do so. Just wanted to make sure the Window was raised or when already active it was raised again.

        Hope this helps a bit.

        Greetz, Jeroen

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          From the look of his code, I'm assuming that it was his program that was crashing, not the client app. (See the note about using this with automatic variables.) More than likely the above code was in a method that was called, the QProcess was instantiated (and unfortunately parented), and then as soon as the method was over, went out of scope and was deleted. But since it was a child of this, then all kinds of nastiness happened.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kitten
            wrote on last edited by
            #5

            i do everything mlong said, and it works fine for me now,and my problem solved ,thanks

            www.kitten.mihanblog.com

            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