Seite 1 von 1

[gelöst] Verständnissproblem mit connect und Typen

Verfasst: 12. Juni 2007 02:05
von Robinayor_
Hi ihrs!

Als kleine Vorwarnung: Ich bin frisch mit C++ und noch frischer mit QT :-)

Ich habe in meinem Programm ein Objekt controller der Klasse PositionController.
Selbige Klasse hat ein Signal ms(QString) welches im Header so definiert wird:

Code: Alles auswählen

       16         signals:
       21                 void ms(QString msg);
im Entsprechenden C++-File emitte ich das Signal dann wie folgt:

Code: Alles auswählen

emit ms(QString msg("bla")); // Normal was dynamisches, aber zum Debuggen lieber einfach halten.
Anschließend lege ich mir zum Debuggen einen QPushButton an, in dem ich über das SIGNAL aus dem PositionController ein "bla" darstellen will und connecte diesen wie folgt:

Code: Alles auswählen

       10         QPushButton test("Hello world!");
       11         test.show();
       12         QObject::connect(controller, SIGNAL(ms(QString)), test, SLOT(setText(QString)));

Wenn ich das ganze nun kompilieren will haut mir mein g++ folgendes um die Ohren:
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:12: error: no matching function for call to ‘QObject::connect(PositionController&, const char [13], QPushButton&, const char [18])’
/usr/include/qt4/QtCore/qobject.h:181: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/include/qt4/QtCore/qobject.h:282: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
Ich verstehe den error nicht ganz, da ja sowohl QPushButton, als auch PositionController Childs vom QObject sind und die ja laut letzer Zeile gefordert werden.

Was übersehe ich da grade?

mfl
Robin

Verfasst: 12. Juni 2007 02:23
von Robinayor_
GNAHAH! ;-)

Nach einer Tasse Kaffe und nochmaligem Lesen der Fehlermeldung ist mir aufgefallen das connect() ja Referenzen auf die Objekte will und nix anderes. Achja - und QPushButton scheint auch kein setText() zu haben - obwohl es das laut Doku von QAbstractButton erben sollte.

Nun gehts auf jeden Fall - Sry fürs unnötige Posten..

mfl
Robin

Verfasst: 12. Juni 2007 06:32
von Christian81
Wenn er von QAbstracButton erbt, hat er auch setText()