QT créant mes objets de formulaire, comment accéder à ce formulaire?

StackOverflow https://stackoverflow.com/questions/1809810

  •  05-07-2019
  •  | 
  •  

Question

J'essaie de modifier un certain message de zone de texte. Il affichera ma sortie.

Voici ce que j'ai dans mon 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);
}
...

Dans ma principale:

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

Maintenant, je sais que je devrais appeler w.changeOutput (s1). Mais le problème est que w n’est pas déclaré dans mon TCPClient.cpp ...

QT a créé la fonction main () pour moi. Je ne sais pas comment résoudre ce problème. Je souhaite pouvoir appeler w.changeOutput (s1) depuis mon fichier TCPClient.cpp.

Ceci est l'erreur im obtenir. TCPClient.cpp: 182: erreur: impossible d'appeler la fonction de membre ‘void virtuel Form2 :: changeOutput (std :: string)’ sans objet

Merci.

Était-ce utile?

La solution

Si j'ai bien compris le problème, je pense que le bon "Qt-way" Ce serait que le client TCP envoie un signal quand il reçoit un message, puis dans votre fonction principale, connectez ce signal au slot changeOutputs.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top