开发者

QT creating my form objects, how to access that form?

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜