Qt World Summit: Submit your Presentation

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

  • I've got these two lines of code:

    @this->twitter = new Twitter();

    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"));


  • 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?

  • 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:


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

  • 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.

  • 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?

  • 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.

  • 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.

  • 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.

Log in to reply