Problem running a qt app.
alain soucy
soucya at videotron.ca
Wed Jun 14 12:13:10 BST 2000
Salut,
lorsqu'on utilise le mécanisme SIGNAL/SLOT il faut auparavant passer le fichier
à un préprocesseur (MOC). Il ne faut pas oublier aussi, d'ajouter dans le
fichier la macro Q_OBJECT.
voici le code modifié pour qu'il fonctionne :
bonne chance !
//FICHIER 'INCLUDE'
#include <qapplication.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <stdlib.h>
class MyApplication : public QApplication
{
Q_OBJECT
public:
MyApplication (int a, char *t[]);
private:
QPushButton *go;
protected slots:
void slotConnect();
};
//FICHIER SOURCE MODIFIE
#include "test.h"
MyApplication::MyApplication (int a, char *t[]) : QApplication (a, t)
{
go = new QPushButton ("Go !");
go->setFont ( QFont ( "Times", 18, QFont::Bold ) );
setMainWidget (go);
go->show();
connect (go, SIGNAL(clicked()),SLOT(slotConnect()));
}
void MyApplication::slotConnect()
{
system ("kvt &");
}
int main( int argc, char **argv )
{
MyApplication a( argc, argv );
return a.exec();
}
ensuite compiler les fichiers de la facon suivante:
1. /usr/lib/qt/bin/moc test.h -omoc_test.cpp
2. g++ test.cpp moc_test.cpp -lqt -I/usr/lib/qt/include -L/usr/lib/qt/lib
-otest
Le mer, 14 jun 2000, David BOURIAUD a écrit :
>
> Hi to all !
> I'm confronted to the following problem :
> I've modified the t2 qt tutorial so as to have a button that would call
> a kvt terminal.
> I'm not writing this app under kdevelop, for, by now, I'd just like to
> know how qt works.
> When I compile the following program, it works fine (eg. The compiler
> does not complain about anything).
> But when I run it, I get the following :
> QObject::connect: No such slot QApplication::slotConnect()
> QObject::connect: (receiver name: 't2')
> What's wrong with my source code ?
> If anyone could help... Thanks by advance !
>
> The source code of my file :
> ----------------------- begin of source code
> ------------------------------
> #include <qapplication.h>
> #include <qpushbutton.h>
> #include <qfont.h>
> #include <stdlib.h>
>
> class MyApplication : public QApplication
> {
> public:
> MyApplication (int a, char *t[]);
> private:
> QPushButton *go;
> protected slots:
> void slotConnect();
>
> };
>
> MyApplication::MyApplication (int a, char *t[]) : QApplication (a, t)
> {
> go = new QPushButton ("Go !");
> go->setFont ( QFont ( "Times", 18, QFont::Bold ) );
> setMainWidget (go);
> go->show();
> connect (go, SIGNAL(clicked()),SLOT(slotConnect()));
> }
>
> void MyApplication::slotConnect()
> {
> system ("kvt &");
> }
>
>
> int main( int argc, char **argv )
> {
> MyApplication a( argc, argv );
> return a.exec();
> }
> ----------------------- end of source code
> --------------------------------
>
> The Makefile provided with the t2 tutorial hasn't been modified at all.
>
----------------------------------------
Content-Type: text/x-vcard; name="david.bouriaud.vcf"
Content-Transfer-Encoding: 8BIT
Content-Description: Card for David BOURIAUD
----------------------------------------
More information about the KDevelop
mailing list