May 16, 2011

Hedge Hedge
Lab Rat
191 posts

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

  1. this->twitter = new Twitter();
  2. 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:

  1. QObject: Cannot create children for a parent that is in a different thread.
  2. (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:

  1. void Twitter::getAccess()  {
  2.  
  3.  
  4.     connect(oauthManager, SIGNAL(temporaryTokenReceived(QString,QString)),
  5.             this, SLOT(onTemporaryTokenReceived(QString, QString)));
  6.  
  7.     connect(oauthManager, SIGNAL(authorizationReceived(QString,QString)),
  8.             this, SLOT( onAuthorizationReceived(QString, QString)));
  9.  
  10.     connect(oauthManager, SIGNAL(accessTokenReceived(QString,QString)),
  11.             this, SLOT(onAccessTokenReceived(QString,QString)));
  12.  
  13.     connect(oauthManager, SIGNAL(requestReady(QByteArray)),
  14.             this, SLOT(onRequestReady(QByteArray)));
  15.  
  16.     oauthRequest->initRequest(KQOAuthRequest::TemporaryCredentials, QUrl("https://api.twitter.com/oauth/request_token"));
  17.  
  18.     oauthRequest->setConsumerKey("xxxx");
  19.     oauthRequest->setConsumerSecretKey("xxxx");
  20.  
  21.  
  22.     oauthManager->setHandleUserAuthorization(true);
  23.  
  24.     oauthManager->executeRequest(oauthRequest);
  25.  
  26. }

6 replies

May 16, 2011

ZapB ZapB
Hobby Entomologist
1423 posts

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?

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

May 16, 2011

Hedge Hedge
Lab Rat
191 posts

I’m using the oAuth-library kQOAuth [gitorious.org].
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:

screenshot

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

May 16, 2011

ZapB ZapB
Hobby Entomologist
1423 posts

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.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

May 16, 2011

Hedge Hedge
Lab Rat
191 posts

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?

May 17, 2011

Kypeli Kypeli
Lab Rat
41 posts

First of all, which version of Qt are you using? Qt recently put QNetworkAccessManager in its own thread [labs.qt.nokia.com] 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.

May 17, 2011

Hedge Hedge
Lab Rat
191 posts

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.

 
  ‹‹ Copy QPixmap, which way is more efficient      [Solved]How to emit signal in diffrent thread ? ››

You must log in to post a reply. Not a member yet? Register here!