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. Threads problem
QtWS25 Last Chance

Threads problem

Scheduled Pinned Locked Moved General and Desktop
17 Posts 8 Posters 6.5k Views
  • 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.
  • F Offline
    F Offline
    florent.revelut
    wrote on last edited by
    #7

    [quote author="MAMartins" date="1302640707"]
    main:
    @
    #include <QtGui/QApplication>
    #include "thread.h"
    #include <QList>
    #include <QDebug>
    #include <QObject>
    #include <QWidget>
    #include <QGraphicsObject>
    #include <QState>
    #include <QGraphicsObject>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    thread * ft = new thread;
    ft->start();
    
    
    return a.exec&#40;&#41;;
    

    }
    @

    as far as I see the apps are the same :o
    [/quote]

    The difference lies in your a.exec().
    In the previous one, you were creating the app on stack then exiting the main funciton, thus exiting program.
    In your second one, you tell the application to start the main thread, leaving time to switch to other threads.

    Most probably,your first application exited directly, without doing anything, while this one waits for you to close the window (or at least, doesn't end itself when processing is over).

    1 Reply Last reply
    0
    • F Offline
      F Offline
      florent.revelut
      wrote on last edited by
      #8

      [quote author="MAMartins" date="1302656456"]Now I'm trying use a thread on the openCV and my program is closing with no specific error in the crash report i have this:
      @

      Thread 7 Crashed:
      0 OpenCV 0x0001209a GOMP_parallel_end + 58
      1 OpenCV 0x00012121 GOMP_parallel_start + 17
      2 OpenCV 0x00335108 cvSetImagesForHaarClassifierCascade + 1560
      3 ??? 0x0000002f 0 + 47
      @
      [/quote]

      I'm not 100% sure, but it smells like NULL pointer dereferencement (0+47 : 0 is base pointer, 47 is offset, sum of them equals 02f, which is invalid address and crashed your program). Now, I definitely lack code to tell more.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #9

        [quote author="florent.revelut" date="1302673342"][quote author="MAMartins" date="1302640707"]
        main:
        @
        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);

        thread * ft = new thread;
        ft->start();
        
        
        return a.exec&#40;&#41;;
        

        }
        @

        as far as I see the apps are the same :o
        [/quote]

        The difference lies in your a.exec().
        In the previous one, you were creating the app on stack then exiting the main funciton, thus exiting program.
        In your second one, you tell the application to start the main thread, leaving time to switch to other threads.

        Most probably,your first application exited directly, without doing anything, while this one waits for you to close the window (or at least, doesn't end itself when processing is over).[/quote]

        a.exec() does not start the main thread, The main thread is started by the OS. a.exec() starts the eventLoop which is used to get UI and other events and deliver them to the corresponding objects. It ius running untill the loop is exited, e.g. by closing all top level windows, calling QApplication::quit, etc...

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #10

          [quote author="florent.revelut" date="1302673593"][quote author="MAMartins" date="1302656456"]Now I'm trying use a thread on the openCV and my program is closing with no specific error in the crash report i have this:
          @

          Thread 7 Crashed:
          0 OpenCV 0x0001209a GOMP_parallel_end + 58
          1 OpenCV 0x00012121 GOMP_parallel_start + 17
          2 OpenCV 0x00335108 cvSetImagesForHaarClassifierCascade + 1560
          3 ??? 0x0000002f 0 + 47
          @
          [/quote]

          I'm not 100% sure, but it smells like NULL pointer dereferencement (0+47 : 0 is base pointer, 47 is offset, sum of them equals 02f, which is invalid address and crashed your program). Now, I definitely lack code to tell more.[/quote]

          I suggest you debug your app and step through the code of the thread. Then you will see which call crashes.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MAMartins
            wrote on last edited by
            #11

            regarding the programs that do the sum, so the first lacked the a.exec()?

            how can I debug my program properly? =/ this is weird because with no thread it runs good =/

            with qdebug I know that the app runs until void faceTracker::detectFaces( IplImage *img ), but after faces = ... i have no qDebug in the console showing

            1 Reply Last reply
            0
            • F Offline
              F Offline
              florent.revelut
              wrote on last edited by
              #12

              [quote author="MAMartins" date="1302685551"]regarding the programs that do the sum, so the first lacked the a.exec()?
              [/quote]

              Yes

              [quote author="MAMartins" date="1302685551"]
              how can I debug my program properly? =/ this is weird because with no thread it runs good =/

              with qdebug I know that the app runs until void faceTracker::detectFaces( IplImage *img ), but after faces = ... i have no qDebug in the console showing
              [/quote]

              Use an actual debugger (gdb, visual studio debugger), it allows to step and inspect stack, variables, memory.

              If it works in single thread context and not in multithread, classical causes are:

              • access to resources from more than one thread without protection (QMutex), leading to corrupted data
              • race conditions between threads (once again, due to missing synchronization)

              Edit: fixed list presentation. Please use * before a list item (or # for numbered lists), not a -; Andre

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #13

                [quote author="MAMartins" date="1302685551"]regarding the programs that do the sum, so the first lacked the a.exec()?

                how can I debug my program properly? =/ this is weird because with no thread it runs good =/
                [/quote]

                Use QtCreator or MSVS etc and set breakpoints.
                If you need help on doing this, have a look at QtCreators docs. Usually it's by pressing "F9" on a line.

                Then call F5 to start debugging.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  azr79
                  wrote on last edited by
                  #14

                  This project is pretty interesting, I always wanted to know how face detect algorithms work. Let me know when finished ;)

                  Azr79

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MAMartins
                    wrote on last edited by
                    #15

                    [quote author="Gerolf" date="1302694209"]
                    [quote author="MAMartins" date="1302685551"]regarding the programs that do the sum, so the first lacked the a.exec()?

                    how can I debug my program properly? =/ this is weird because with no thread it runs good =/
                    [/quote]

                    Use QtCreator or MSVS etc and set breakpoints.
                    If you need help on doing this, have a look at QtCreators docs. Usually it's by pressing "F9" on a line.

                    Then call F5 to start debugging.

                    [/quote]
                    I'll try to find my error using the debugger, i'll keep you guys posted :)

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Polto
                      wrote on last edited by
                      #16

                      www.remnum.com

                      this is a video about building opencv libs on windows and mac os you can download it
                      with a project for opencv + qt using thread and it is run good try it

                      Polto

                      1 Reply Last reply
                      0
                      • W Offline
                        W Offline
                        webmaster.skelton
                        wrote on last edited by
                        #17

                        I do not know if this makes a difference or not(as it seems you are not using the signal/slot mechanism) but calling exec() within your run reimplementation allows the thread to run in its own event loop. This tends to prevent some memory allocation issues and allows for thread safe usage of signals and slots. Like i said I do not know if this will hold any relevance in your case.

                        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