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 9104137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:47:41+00:00 2026-06-17T01:47:41+00:00

I did serious mistake when I was doing some project and now I have

  • 0

I did serious mistake when I was doing some project and now I have to re-program it from bottom.. I’m writing multi-threaded server which will handle connections, requests, etc.. But, when I created new class with base object of QThread, I was starting thread with QThread->run(), not QThread->start(). Now I get bunch of errors. Here’s situation.
I have server, which creates new threads on each connection and starts reading data from each connected client.When I receive data, it emits signals which is connected to main GUI class and displays result OK. It also saves socket handle for replying messages. When I write data to socket from GUI class, it says this:

QObject: Cannot create children for a parent that is in a different thread.
(Parent is QNativeSocketEngine(0x23a6c38), parent’s thread is MyThread(0x1fb8670), current thread is QThread(0x9eb980)

What’s wrong?

  • 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-17T01:47:42+00:00Added an answer on June 17, 2026 at 1:47 am

    I know QT but am not intimately familiar with the QT socket implementation itself, but from the sound of your error message and the way you describe your design, your problem is not related to QT but to thread/socket architecture in general. Multi-threaded applications requiew careful thought intelligent design to be efficient and ensure that your session data etc is consistent and not fraught with concurrency problems, orphaned data structures etc.

    It also saves socket handle for replying messages. When I write data to socket from GUI class, it says this…:

    Without knowing all the details of your implementation, if you persisted the socket handle in thread 1 to respond to a call in thread 1, and then tried to write data to it from a call using thread 2, that original socket handle is invalid in the context of thread 2. This may explain your error message.

    Persisting a socket handle for subsequent calls is not a good way to do things for any number of reasons (including the problem you are encountering.) Why are you doing that? If you need to persist client information across calls, use session structures to persist that data. If you want to keep the whole thread alive while the conversation back and forth continues, design your thread/socket interactions to behave that way and consider a thread pool, etc. But you should not have orphaned sockets just hanging around – each must exist in its own thread context and has no valid handle outside of its ‘home’ thread.

    When a socket is finished with its conversation, the thread that was spawned and the socket created in that thread to continue the conversation are DONE – it should ALL be cleaned up.

    If I understand your implementation correctly, my suggestions should fix your problem.

    In your comment you mention:

    “socket as a global variable” – you should NOT be using a global socket in such a way, if I understand correctly what you’re doing.

    Your server app should have a main thread with a persistent socket that listens for requests, when you get a request coming in there should be a signal emitted and the slot for that signal should spawn a thread that initializes a new socket for handing that request. Handle the request in the thread, then clean everything up, etc.

    If you need to extract information from incoming requests and persist it somewhere, do it in the main thread and other threads should have no access to the structures you use to persist for that session in the main thread (unless you use synchronization mechanisms) Same thing if you want to get information out of the request processing when it’s done – get it back out of the spawned thread into the main thread through a signal emitted when the thread terminates.

    If you don’t follow these rules, you need to use synchronization objects or you’ll have all kinds of problems, including what you’re experiencing, judging from the sound of your error message.

    In short: “What happens in a thread, stays in a thread”

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

Sidebar

Related Questions

I have some serious issues...I need to build a project from another developer in
It's been a while since I did serious web development. Now I meet a
I never did any serious Java coding before, but I learned the syntax, libraries,
The last time I did any serious Java coding was back around the turn
Did some searches here & on the 'net and haven't found a good answer
Did you ever have the following situation: you need to store information, but a
Did not have luck with these examples: Javascript File remove Javascript FSO DeleteFile Method
So I've never done any assembly programming (although I did some reading/reasoning out the
I have been doing a lot of searching and still can't seem to figure
Ok... serious problem. I did the update , thinking that I could continue to

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.