Thought I'd post this here as there seem to be a few switched on people here.
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..
And the qthread object...
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:
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
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..
Code:
class Output : public QWidget
{
public:
Output(QWidget *parent = 0);
public slots:
void displayMsg(QString msg);
private:
QTextEdit *display;
};
And the qthread object...
Code:
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);
}
*/
}
I get the compile time error:
Code:
main.cpp: In member function 'virtual void MyThread::run()':
main.cpp:94: error: cannot call member function 'void Output::displayMsg(QString)' without object
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