Bonjour forum,
je suis entrain de compiler un code qui teste l appuie d'un key et qui fait un appel periodique d'une fonction compte() mais la compilation me donne une erreur que j arrive pas à la resoudre.
clavier.h:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef CLAV_H
#define CLAV_H
#include <QtGui>
#include <QtGui>
#include <QtCore>
void go();
int i=0;
void f(int x,QKeyEvent *event);
//void compte();
class MyTest : public QWidget
{
    Q_OBJECT;
    public:
        MyTest (  QWidget * parent = 0, Qt::WindowFlags f = 0  ) : QWidget  (parent,f )
            {
 
            };
 
    protected:
        QTimer *timer;
        void keyPressEvent(QKeyEvent *event)
            {
                //qDebug()<<event->text();
                int k = event->key();
                f(k,event);
            };
    public slots:
            void compte();
 
    public:
            void go()
                {
                    timer = new QTimer(this);
                    connect(timer, SIGNAL(timeout()), this, SLOT(compte()));
                    timer->start(1000);
                };
 
};
 
void MyTest::compte()
    {
 
        do
            qDebug()<< i++;
 
            while (i<11);
    };
void f(int x,QKeyEvent *event)
{
    if (x==Qt::Key_M)   qDebug()<< '2';
    event->accept();
 
};
#endif
main.cpp:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
#include "clav.h"
MyTest *window1;
int main(int argc, char** argv)
{
	QApplication app(argc, argv);
     window1= new MyTest();
 
    window1->go();
    window1-> resize(200,200);
	window1->show();
	return app.exec();
}
et pour l erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
C:\Documents and Settings\AISEIR\Mes documents\clavier>make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Documents and Settings/AISEIR/Mes docume
nts/clavier'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -
DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"..\..\..\..\Qt\2009.01
\qt\include\QtCore" -I"..\..\..\..\Qt\2009.01\qt\include\QtGui" -I"..\..\..\..\Q
t\2009.01\qt\include" -I"." -I"..\..\..\..\Qt\2009.01\qt\include\ActiveQt" -I"de
bug" -I"." -I"..\..\..\..\Qt\2009.01\qt\mkspecs\win32-g++" -o debug\main.o main.
cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
oc -Wl,-subsystem,console -mthreads -Wl -o debug\clavier.exe debug/main.o  -L"c:
\Qt\2009.01\qt\lib" -lQtGuid4 -lQtCored4
debug/main.o: In function `ZN6QFlagsIN2Qt10WindowTypeEEC1ERKS2_':
C:/Documents and Settings/AISEIR/Mes documents/clavier/clav.h:(.text$_ZN6MyTestC
1EP7QWidget6QFlagsIN2Qt10WindowTypeEE[MyTest::MyTest(QWidget*, QFlags<Qt::Window
Type>)]+0x38): undefined reference to `vtable for MyTest'
C:/Documents and Settings/AISEIR/Mes documents/clavier/clav.h:(.text$_ZN6MyTestC
1EP7QWidget6QFlagsIN2Qt10WindowTypeEE[MyTest::MyTest(QWidget*, QFlags<Qt::Window
Type>)]+0x44): undefined reference to `vtable for MyTest'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\clavier.exe] Error 1
mingw32-make[1]: Leaving directory `C:/Documents and Settings/AISEIR/Mes documen
ts/clavier'
mingw32-make: *** [debug] Error 2