Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8005051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:06:33+00:00 2026-06-04T17:06:33+00:00

I have the following problem: Our main application uses the Qt toolkit for showing

  • 0

I have the following problem: Our main application uses the Qt toolkit for showing windows and user interaction. A large part of our application, however, is ignorant of the GUI part. I now created the following design:

  • There is a singleton class that may request rendering for a given object (OpenSceneGraph node; but this is irrelevant for the question)
  • The rendering request causes the singleton to emit a signal
  • There is a slot in the main window class (which uses Qt) to handle rendering the object
  • Currently, the slot only creates a new text edit widget and places it in an QMdiArea of the main window

However, the application inevitably crashes when I try to create a new widget. The error messages area:

QObject::setParent: Cannot set parent, new parent is in a different thread
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
myApplication: ../../src/xcb_io.c:178: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Aborted

After perusing stackoverflow, I found similar questions (which were not readily applicable to this situation). Obviously, Qt doesn’t like it when I change something in the main window from another thread. However, I did not consciously create the new thread and I thought that the singleton (which is created in the main function right after a call to QApplication()) should be in the same thread as Qt. Apparently, I am mistaken.

Here is a minimal example that shows the things I am doing (I have extracted the relevant parts of the code, so the example is not exactly functional):

class Object
{
public:
};

class Singleton
{
public:
  typedef boost::signals2::signal<void (Object*)> signalShowObject;
  signalShowObject _showObject;
};

class MainWindow : public QMainWindow
{
public:
  MainWindow()
  {
    Singleton::getInstance()->_showObject.connect( boost::bind(&MainWindow::showObject, this, _1) );

    // Set up MDI area etc.
  }

private:
  QMdiArea* _mdiArea;

  void showObject(Object* object)
  {
    // Creating a new subwindow here causes the crash. The `object` pointer is
    // not used and has just been included because it models my real problem
    // better.
    _mdiArea->addSubWindow( new QTextEdit() )->show();
  }
};

My attempts to solve this problem have been very clumsy:

  • I created a new Qt signal in the MainWindow class with the same signature as the Boost signal
  • In the slot that handles the Boost signal, I emit the new Qt signal, passing the pointer over
  • I now created a new Qt slot that receives the pointer

When I open a new window in the new slot, everything works. However, this strikes me as very clumsy. Do I have to cascade all Boost signals like that or is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:06:34+00:00Added an answer on June 4, 2026 at 5:06 pm

    I think what is confusing is that the call to the singleton from the rendering request is being made from whatever thread is generating the request. The singleton will return a unique object, but the signal it sends it still in the context of the requesting thread. Something has to be done to explicitly cause or allow a thread context switch to the main UI thread in order to actually process this signal and create the UI objects in the main thread.

    And you are doing this implictly in this sequence you describe:

    •I created a new Qt signal in the MainWindow class with the same
    signature as the Boost signal

    •In the slot that handles the Boost signal, I emit the new Qt signal,
    passing the pointer over

    •I now created a new Qt slot that receives the pointer

    Qt signals and slots automatically queue cross-thread signals (note 1). So the slot that handles the Boost signal is still in the requesting thread. It then emits the Qt signal. Qt detects that the receiver of the signal is in the main thread (note 2) but the sender is in the requester thread, and queues the signal. When the main Qt event loop in the main thread pulls this queued event off the event list, it then automatically re-emits the signal, but now it is in the main thread context and UI operations are allowed.

    note 1 – unless this behavior is explicitly overridden in the connect() call – see the documentation for Qt::ConnectionType.

    note 2 – really, that the QObject of the receiver is owned by the main thread. Every QObject retains the thread id of the thread context it was created in.

    I hope this helps explain what is happening with the threads. Your solution is fine, but as @tmpearce suggested it might be convenient to wrap things up in an adapter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: I implemented a managed mobile application for Windows Mobile
I have the following problem: In our application we have a list of reports
I have following problem: I have built a tabbar application with 4 tabs. I
I have a following problem: I compiled my application on Linux Ubuntu 9.10 using
Our application have several EARs deployed to a single JBOSS-AS. Every EAR uses SLF4J
We have following table structure for our problem domain - Questionnaire - QuestionnaireID (Primary
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have the following problem: I have a form in site/banen (currently local running
I have the following problem. I have three classes, A, B and C. A
I have the following problem that the standard library doesn't solve well, and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.