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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:13:34+00:00 2026-05-20T11:13:34+00:00

The title is very cryptic, so here goes! I am writing a client that

  • 0

The title is very cryptic, so here goes!

I am writing a client that behaves in a very synchronous manner. Due to the design of the protocol and the server, everything has to happen sequentially (send request, wait for reply, service reply etc.), so I am using blocking sockets. Here is where Qt comes in.

In my application I have a GUI thread, a command processing thread and a scripting engine thread. I create the QTcpSocket in the command processing thread, as part of my Client class. The Client class has various methods that boil down to writing to the socket, reading back a specific number of bytes, and returning a result.

The problem comes when I try to directly call Client methods from the scripting engine thread. The Qt sockets randomly time out and when using a debug build of Qt, I get these warnings:

QSocketNotifier: socket notifiers cannot be enabled from another thread
QSocketNotifier: socket notifiers cannot be disabled from another thread

Anytime I call these methods from the command processing thread (where Client was created), I do not get these problems.

To simply phrase the situation:

Calling blocking functions of QAbstractSocket, like waitForReadyRead(), from a thread other than the one where the socket was created (dynamically allocated), causes random behaviour and debug asserts/warnings.

Anyone else experienced this? Ways around it?

Thanks in advance.

  • 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-20T11:13:35+00:00Added an answer on May 20, 2026 at 11:13 am

    I’m assuming that you’re using QThread for the threading operations. If so, you can either a) use queued signal-slot connections; or b) explicitly use the QThread’s event loop by creating a custom event type, posting that event in your scripting engine, and then having the client class handle those events.

    example for a)

    class ClientThread : public QThread
    {
        ..stuff..
    public slots:
       waitForReadyRead();
    };
    
    class ScriptEngineThread : public QThread
    {
        ..other stuff..
     signals:
        void requestWaitForReadyRead();
    };
    
    // In the ScriptEngineThread implementation...
    ScriptEngineThread::setupClient()
    {
       connect(this, SIGNAL(requestWaitForReadyRead()),
          client_, SLOT(waitForReadyRead()),
          Qt::QueuedConnection);
    }
    

    Then, whenever you want to do the socket operations, just emit ScriptEngineThread::requestWaitForReadyRead();. The major difficulty is, I assume, you need the scripting thread to wait for some socket operation to be done. In this case you’ll need to fire signals back and forth between the threads, causing some circular dependancy.

    For alternative b, it would require a little more coding work, but you could:

    • Create your own subclasses of QEvent
    • Create a class to operate as a middleman, posting and handling each of your QEvents and emitting signals to communicate with the threads – each thread can have an instance of this
    • Connect the client and script engine to the event signals it cares about.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that the title is very subtle but I have absolutely no idea
First of all, the title is very bad, due to my lack of a
First off, I'm not entirely sure that my question title is very descriptive, so
Sorry about the title. I do realize it's not very descriptive. :| Here is
Ok, I have a model that is very simple: ServiceType(id: integer, title: string, duration:
I'm not sure if the title is very clear, but basically what I have
Title: Eclipse plug-in development Unable to instantiate class due to java.lang.NoClassDefFoundError: Trying to build
Title more or less says it all. Specifically, I've become increasingly annoyed that in
The title is very descriptive. Just in case, I will give an example: START
I don't now if this title is very clear, but I would like 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.