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

  • Home
  • SEARCH
  • 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 6873811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:06:59+00:00 2026-05-27T04:06:59+00:00

I’m working on a chat program where the client is single-threaded but the server

  • 0

I’m working on a chat program where the client is single-threaded but the server will start a new thread for each connected client. I believe my client code is solid but the server has me bewildered.

Right now, I have a derived QTcpSocket class that looks for incoming connections and when it see’s one, begins a new QThread. When the QThread runs, it creates an instance of a QMainWindow (which is the chat window) and shows it.

void secureserver::incomingConnection(int socketDescriptor)
{
    securethread *thread = new securethread(socketDescriptor, this);
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    thread->start();
}

void securethread::run()
{
    serverwindow myServerWindow;
    myServerWindow.setSocketDescriptor(mySocket);
    myServerWindow.show();
}

I’ve been getting errors to stderror like the following, and the QMainWindow never appears so chatting is impossible at this point.

QObject: Cannot create children for a parent that is in a different thread.
(Parent is QApplication(0xbf9e5358), parent's thread is QThread(0x98a54f0), current thread is securethread(0x99e9250)
QPixmap: It is not safe to use pixmaps outside the GUI thread

My questions are:

  • Do I need to make the QThread a parent of the QMainWindow?
  • Am I going about this in the completely wrong way?
  • Any other general ideas on why this isn’t working as I expect it to
    or how to fix it would be greatly appreciated as well.
  • 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-05-27T04:06:59+00:00Added an answer on May 27, 2026 at 4:06 am

    Yes, you are going about this in the wrong way. GUIs, due to platform limits, are single threaded systems. You cannot create, change and manage GUI objects on different threads – everything must be done on one thread (normally, the GUI thread).

    Qt has two mechanisms for dealing with worker threads and the GUI: queued signals and slots, and the QCoreApplication::postEvent() handler.

    More details are in the comprehensive Qt threading document: http://doc.qt.io/qt-5/thread-basics.html

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Specifically, suppose I start with the string string =hello \'i am \' me And
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.