我正在尝试更改某个文本框消息。它将显示我的输出。
这就是我在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);
}
...
在我的主要:
#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();
}
现在,我知道我应该调用w.changeOutput(s1)。 但问题是,w未在我的TCPClient.cpp中声明...
QT为我做了main()函数。我不知道如何解决这个问题。我希望能够从我的TCPClient.cpp中调用w.changeOutput(s1)。
这是我得到的错误。 TCPClient.cpp:182:错误:无法调用成员函数'virtual void Form2 :: changeOutput(std :: string)'没有对象
感谢。
答案 0 :(得分:2)
如果我正确理解了问题,我认为正确的“Qt-way”是让TCP客户端在收到消息时发送信号,然后在主函数中将该信号连接到changeOutputs插槽。 / p>