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. "QObject: Cannot create children for a parent that is in a different thread." -> only in release-mode
Forum Updated to NodeBB v4.3 + New Features

"QObject: Cannot create children for a parent that is in a different thread." -> only in release-mode

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 9.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.
  • H Offline
    H Offline
    Hedge
    wrote on last edited by
    #1

    I've got these two lines of code:

    @this->twitter = new Twitter();
    twitter->getAccess();@

    getAccess authorizes the application via oAuth (makes a few http-requests)

    When I execute it in debug-mode it works flawless, but in release-mode I get this error:

    @QObject: Cannot create children for a parent that is in a different thread.
    (Parent is Twitter(0x11dc89b0), parent's thread is QThread(0xc3eabe8), current thread is QThread(0xf6872f8)@

    How can I fix this?

    This is the getAccess()-function:

    @void Twitter::getAccess() {

    connect(oauthManager, SIGNAL(temporaryTokenReceived(QString,QString)),
            this, SLOT(onTemporaryTokenReceived(QString, QString)));
    
    connect(oauthManager, SIGNAL(authorizationReceived(QString,QString)),
            this, SLOT( onAuthorizationReceived(QString, QString)));
    
    connect(oauthManager, SIGNAL(accessTokenReceived(QString,QString)),
            this, SLOT(onAccessTokenReceived(QString,QString)));
    
    connect(oauthManager, SIGNAL(requestReady(QByteArray)),
            this, SLOT(onRequestReady(QByteArray)));
    
    oauthRequest->initRequest(KQOAuthRequest::TemporaryCredentials, QUrl("https://api.twitter.com/oauth/request_token"));
    
    oauthRequest->setConsumerKey("xxxx");
    oauthRequest->setConsumerSecretKey("xxxx");
    
    
    oauthManager->setHandleUserAuthorization(true);
    
    oauthManager->executeRequest(oauthRequest);
    

    }@

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      You have not shown any indication as to where these objects are created w.r.t. the threads that they are supposed to have affinity with. Could you post some more relevant code and explain what the expected threading model is please?

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hedge
        wrote on last edited by
        #3

        I'm using the "oAuth-library kQOAuth":http://gitorious.org/kqoauth/kqoauth.
        The class Twitter is basically the example-class from the kQOAuth-library (without the main-function).

        There is basically no threading-model.
        My main-function creates an instance of IcecastServer which has a member QTcpServer (which creates its own threads I assume).
        IcecastServer also contains the member twitter.

        My GUI is QML (Jens's desktop components) and connected to IcecastServer via the class QmlTcpMediator.

        Even if I call twitter->getaccess() in the concstructor of IcecastServer (which is just an instance in the main-function) I get this error. So I guess it has something to do with the kQOAuth library I am using.

        EDIT: For now I can't even execute my application in release-mode anymore. It just quit with a negative error-code after starting. starting debug in release-mode gives me this screen:

        !http://img29.imageshack.us/img29/7798/signalreceived.png(screenshot)!

        In the meantime my program still works perfectly in debug-mode.

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #4

          From your latest post it sounds as if you are linking and running against different libs. Is this the case? Check your %PATH% environment variable to make sure the runtime linker is picking up the same libraries as the build time linker.

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hedge
            wrote on last edited by
            #5

            I did. They are exactly the same.

            Qt Creator offered me the option to "import existing build" for the release-configuration. I pressed it.
            For some reasons the program works now in release-mode as well and doesn't crash anymore.

            Although I'm a big friend of that Qt-magic could you explain what could have happened there?

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kypeli
              wrote on last edited by
              #6

              First of all, which version of Qt are you using? "Qt recently put QNetworkAccessManager in its own thread":http://labs.qt.nokia.com/2011/04/29/threaded-http-inside-qnetworkaccessmanager/ so if you have a version of Qt from Git, this can be the source of the error. In that case, better file a bug to Qt.

              But have you checked what IcecastServer is doing? Does it have threads?

              kQOAuth does not create threads explicitly.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hedge
                wrote on last edited by
                #7

                Hello Johan,

                I'm using Qt version 4.7.3 (not from git)

                IcecastServer is my own class. It has a QTcpServer-member but the relevant code gets executed in IcecastServer's constructor.

                Since IcecastServer is instanced in the main-function I doubt it runs in its own thread.

                debug and release build deploy to the same folder now (after hitting import existing build). It works this way for both configs. I'll have a deeper look in it soon but getting the tool out is 1st priority for me now.

                1 Reply Last reply
                0
                • MattMM Offline
                  MattMM Offline
                  MattM
                  wrote on last edited by MattM
                  #8

                  I know this thread is really old, but I stumbled on it today searching for a solution to a similar problem. Maybe someone else can benefit from my experience.
                  I was getting the "Cannot create children for a parent that is in a different thread" error in a QTCPServer derived class. But I only saw the error in Debug.
                  @ZapB gave a hint about running against different libs. And Sure enough, my debug configuration was linking against QCore4.lib and QCored4.lib. Both DLLs were loaded in memory. After I cleaned that up, the Debug configuration ran with no problems.

                  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