C++ QT创建我的表单对象,如何访问该表单?

C++ QT创建我的表单对象,如何访问该表单?,c++,qt,C++,Qt,我正在尝试更改某个文本框消息。它将显示我的输出 这是我在TCPClient()中的内容 182::Form2::changeOutput(s1) 在我看来: #include <qapplication.h> #include "form2.h" #include <string.h> /* for memset() */ #include <iostream> #include <stdlib.h> /* for atoi() a

我正在尝试更改某个文本框消息。它将显示我的输出

这是我在TCPClient()中的内容

182::Form2::changeOutput(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();
}
#包括
#包括“表格2.h”
#包含/*用于memset()*/
#包括
#对于atoi()和exit(),包含/*)*/
int main(int argc,字符**argv)
{
质量保证申请a(argc、argv);
Form2W;
w、 show();
a、 连接(&a,信号(lastWindowClosed()),&a,插槽(quit());
返回a.exec();
}
现在,我知道我应该调用w.changeOutput(s1)。 但问题是,w并没有在我的TCPClient.cpp中声明

QT为我创建了main()函数。我不知道如何解决这个问题。我希望能够从TCPClient.cpp中调用w.changeOutput(s1)

这就是我遇到的错误。 TCPClient.cpp:182:错误:无法在没有对象的情况下调用成员函数“virtual void Form2::changeOutput(std::string)


谢谢。

如果我正确理解了这个问题,我认为正确的“Qt方式”应该是让TCP客户端在收到消息时发送一个信号,然后在主功能中将该信号连接到changeOutputs插槽

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();
}