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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:21:45+00:00 2026-06-10T00:21:45+00:00

I have a Thread class thats derives from QThread: class Thread : public QThread

  • 0

I have a Thread class thats derives from QThread:

class Thread :
    public QThread
{
    Q_OBJECT
public:
    Thread(QObject* parent = NULL);
    ~Thread(void);

    virtual void run();
    void stop();

public slots:
    virtual void OnMessage(const char* msg);

protected:
    bool m_Done;
};

And a derived class:

class DerivedThread: public Thread
{
    Q_OBJECT
public:
    virtual void run();

    ~DerivedThread();

public slots:
    virtual void OnMessage(const char* msg);

private:
    IQFeedSocket* m_Socket;
};

This is pretty straight forward. Then I have a Socket wrapper class that takes a Thread object in its constructor:

class IQFeedSocket : public QObject
{
    Q_OBJECT

public:
    IQFeedSocket(Thread *parent);
    ~IQFeedSocket();

    bool Connect(int port);
    bool Write(const char* msg);

public slots:
    void OnMessage();

signals:
    void SendMessage(const char* msg);

private:
    QTcpSocket* m_Socket;
    char* m_ReceiveBuffer;
};

Now, I do call exec() in my DerivedThread::run() method, and it is successful because I get the OnMessage() call in the socket object, which is instantiated within the thread.
What I want to do is pretty simple: In the IQFeedSocket::OnMessage, I will check that the message receive is completed (it has to end in “\r\n”) and when a complete message is received, forward it to my Thread object that is registered in the constructor.
So, in my IQFeedSocket constructor, I do this:

IQFeedSocket::IQFeedSocket(Thread *parent)
    : QObject(parent)
{
    m_ReceiveBuffer = new char();
    connect(this,SIGNAL(SendMessage(const char*)), this->parent(), SLOT(OnMessage(const char*)));
}

And in the OnMessage() method:

void IQFeedSocket::OnMessage()
{
    const char* msg;
    if(m_Socket->bytesAvailable() != 0) //More stuff needed
    {
        QByteArray msgArray = m_Socket->readAll();
        msg = msgArray;
        emit SendMessage(msg);
    }
}

When I debug, I get to the emit line, but then the OnMessage(char*) method from the DerivedThread object is never called. I’m sure it’s a pretty simple oversee, but I can’t seem to spot where I’m going wrong. Any Ideas? thx!

The DerivedThread::OnMessage(char*):

void DerivedThread::OnMessage(const char* msg)
{
        //This never gets called :(
    printf(msg);
    char* f;
    strcpy(f,msg);
}

EDIT: I have also tried the connect() on the DerivedThread side:

m_Socket = new IQFeedSocket(this);
connect(m_Socket, SIGNAL(SendMessage(const char*)), this, SLOT(OnMessage(const char*)));
Thread::exec();

But with no luck.

  • 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-10T00:21:46+00:00Added an answer on June 10, 2026 at 12:21 am

    The arguments in the signal/slot definition and the connect call have to match EXACTLY including const.

    Even using a typedef in one and the full name in the other is enough to break it.

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

Sidebar

Related Questions

I have a class 'Downloader' derived from QObject that runs in a worker thread.
I have a helper class that should only ever run in a background thread.
I have a class class with main thread public class MainThread extends Thread {
I have an object that is derived from QThread and the class definition includes
I have a button class thats created from within the onSurfaceCreated method in my
I have created a class that derives from TThread, because I wish to do
I have a custom observer class derived from CBase , MConnectionMonitorObserver , and QObject
I have a worker thread in a class that is owned by a ChildView.
I have a custom thread pool class, that creates some threads that each wait
In Java I have the necessity of implementing a class that extends Thread within

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.