I'm coding a small front end GUI for some chat client code I've written in C. I'm not really worrying about the networking aspect yet, just getting the GUI and signals set up etc.
Here's what the app looks like, it's pretty simple, type input, click submit, it (will eventually) sends the message to the chat server.

I've tried to set up a new qthread object to deal with the task of continually checking for messages sent by the chat server. The problem is when it finds one I want it to update the main "display" with the received message. I've written code to that effect but it doesn't work.
Here's the relevent code segments:
This is the main "display" window..
{
public:
public slots:
private:
};
class Output : public QWidget
{
public:
Output(QWidget *parent = 0);
public slots:
void displayMsg(QString msg);
private:
QTextEdit *display;
};
To copy to clipboard, switch view to plain text mode
And the qthread object...
{
protected:
void run();
};
void MyThread::run()
{
for (int count = 0; count < 20; count++)
{
sleep(1);
Output::displayMsg("test");
}
/*char *rawmessage = (char *)malloc(MAX_MSG_LENGTH);
while(1)
{
//rawmessage = network_getmessage();
// translate from char * to QString
//displayMsg(msg);
}
*/
}
class MyThread : public QThread
{
protected:
void run();
};
void MyThread::run()
{
for (int count = 0; count < 20; count++)
{
sleep(1);
Output::displayMsg("test");
}
/*char *rawmessage = (char *)malloc(MAX_MSG_LENGTH);
while(1)
{
//rawmessage = network_getmessage();
// translate from char * to QString
//displayMsg(msg);
}
*/
}
To copy to clipboard, switch view to plain text mode
You can see I've commented out the network stuff, I just want to get the threads communicating in a basic way before I move on.
I get the compile time error:
main.cpp: In member function 'virtual void MyThread::run()':
main.cpp:94: error: cannot call member function 'void Output::displayMsg(QString)' without object
main.cpp: In member function 'virtual void MyThread::run()':
main.cpp:94: error: cannot call member function 'void Output::displayMsg(QString)' without object
To copy to clipboard, switch view to plain text mode
I can post the full source if it will help, but I think the parts above are all that is needed?
tl;dr version: how can I call another class's member functions from within a qthread object?
Thanks, Benjamin
Bookmarks