Question

I am trying to change a certain text box message. It will display my output.

This is what I have in my TCPClient()

#include "form2.h"....string recvMSG = "random";    
QString s1 = QString::fromLocal8Bit(recvMSG.c_str());

182:: Form2::changeOutput(s1);

within my form2.h I have:

...
void Form2::changeOutput(QString &s)
{
    output_box.setText(s1);
}
...

In my main:

#include <qapplication.h>
#include "form2.h"
#include <string.h>     /* for memset() */
#include <iostream>
#include <stdlib.h>     /* for atoi() and exit() */

int main( int argc, char ** argv )
{
    QApplication a( argc, argv );
    Form2 w;
    w.show();
    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    return a.exec();
}

Now, I know I should be calling w.changeOutput(s1). But problem is, w isn't declared within my TCPClient.cpp...

QT made the main() function for me. I am not sure how to solve this problem. I want to beable to call w.changeOutput(s1) from within my TCPClient.cpp.

This is the error im getting. TCPClient.cpp:182: error: cannot call member function ‘virtual void Form2::changeOutput(std::string)’ without object

Thanks.

Was it helpful?

Solution

If I understood the problem correctly, I think the proper "Qt-way" would be to have the TCP client send a signal when it receives a message, and then in your main function connect that signal to the changeOutputs slot.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top