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. QProcess crashes
Forum Updated to NodeBB v4.3 + New Features

QProcess crashes

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

    I'm trying to verify if the process is already running, if it's running closes and creates a new process.

    @QProcess *MyProcess;@

    @ if(MyProcess!= NULL)
    {

        MyProcess->kill();
    
    }
    
    MyProcess = new QProcess(this);@
    

    My application crashes!

    -- 0x00

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

      Just because the pointer "MyProcess" is not NULL, doesn't mean it's a valid pointer!

      It might be a dangling pointer, i.e. a pointer to an object that has already been deleted/destroyed.

      Any attempt to dereference a dangling pointer will result in undefined behavior (crash).

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Besides the fact that you don't actually initialize MyProcess variable to NULL (maybe in your code you do) it's not the way to check if process is running. there is a method state() that returns current state of the process - not running, running or starting.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          beowulf
          wrote on last edited by
          #4

          Even if the checking process status he continues crashing

          @ if(MyProcess->state() == QProcess::Running)
          {

              MyProcess->kill();
          
          }@
          

          -- 0x00

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on last edited by
            #5

            You still are dereferencing the "MyProcess" pointer. But is that pointer valid at all ???

            I mean: Do you assign the address of a QProcess object to that pointer before you try to dereference?

            Also, as said before, you also have problem if the object has already been deleted/destroyed...

            (If you get a crash on pointer access, it's almost always either a NULL pointer or a dangling pointer!)

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            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