bonjour !
je souhaiterais faire un programe de gestion de location, je vien juste de le commencer, et je n'arrive pas a le compiler.
a la compilation(codeblock avec mingw32), il me donne ça :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
Switching to target: default
Compiling: window.cpp
Compiling: main.cpp
Linking executable: C:\C++\Location Manager\Location Manager.exe
.objs\window.o:window.cpp:(.text+0x170): undefined reference to `vtable for MainWindow'
.objs\window.o:window.cpp:(.text+0x17c): undefined reference to `vtable for MainWindow'
.objs\window.o:window.cpp:(.text+0x3a4): undefined reference to `vtable for MainWindow'
.objs\window.o:window.cpp:(.text+0x3b0): undefined reference to `vtable for MainWindow'
.objs\window.o:window.cpp:(.text$_ZN10MainWindow2trEPKcS1_[MainWindow::tr(char const*, char const*)]+0x1c): undefined reference to `MainWindow::staticMetaObject'
.objs\main.o:main.cpp:(.text$_ZN10MainWindowD1Ev[MainWindow::~MainWindow()]+0xb): undefined reference to `vtable for MainWindow'
.objs\main.o:main.cpp:(.text$_ZN10MainWindowD1Ev[MainWindow::~MainWindow()]+0x17): undefined reference to `vtable for MainWindow'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 8 seconds)
si je supprime la ligne Q_OBJECT(window.h), il marche mais ne peux pas utiliser la fonction about(); de mainWindow en passant par connect.

voici mon code :

main.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
#include "window.h"
 
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    MainWindow window;
    window.show();
    return app.exec();
}
window.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
#include <QMainWindow>
#include <QtGui>
#include <QApplication>
#include <QMessageBox>
#include <QObject>
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
 
    public:
        MainWindow();
 
    private slots:
        void inserer();
        void au_sujet();
        void aide();
 
    private:
        QMenu *file_menu;
        QMenu *aide_menu;
        QAction *inserer_act;
        QAction *about_act;
        QAction *aide_act;
        QMessageBox *message_about;
 
        void createActions();
        void createMenus();
 
};
window.cpp

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
#include "window.h"
 
MainWindow::MainWindow()
{
    statusBar()->showMessage(tr("Bienvenue !"));
 
    setWindowTitle(tr("Location Manager"));
    setMinimumSize(160, 160);
    resize(480, 320);
 
    createActions();
    createMenus();
}
 
void MainWindow::inserer()
{
}
 
void MainWindow::au_sujet()
{
    QMessageBox::about(this, tr("About Menu"),tr("The <b>Menu</b> example shows how to create ""menu-bar menus and context menus."));
}
 
void MainWindow::aide()
{
}
 
void MainWindow::createActions()
{
    inserer_act = new QAction(tr("&Inserer"), this);
    inserer_act->setShortcut(tr("Ctrl+K"));
    inserer_act->setStatusTip(tr("Enregistrer une reservation"));
    connect(inserer_act, SIGNAL(triggered()), this, SLOT(inserer()));
 
    about_act = new QAction(tr("&Au sujet de"), this);
    about_act->setShortcut(tr("Ctrl+M"));
    about_act->setStatusTip(tr("Voir les informations relative a cette application"));
    connect(about_act, SIGNAL(triggered()), this, SLOT(au_sujet()));
 
    aide_act = new QAction(tr("&Aide"), this);
    aide_act->setShortcut(tr("Ctrl+P"));
    aide_act->setStatusTip(tr("Aide, pour vous aider a utiliser ce programme"));
    connect(aide_act, SIGNAL(triggered()), this, SLOT(aide()));
}
 
void MainWindow::createMenus()
{
    file_menu = menuBar()->addMenu(tr("&Fichier"));
    file_menu->addAction(inserer_act);
 
    aide_menu = menuBar()->addMenu(tr("&Aide"));
    aide_menu->addAction(aide_act);
    aide_menu->addAction(about_act);
}
a ce que j'ai compris, j'ai besoin de la macro Q_OBJECT pour pouvoir utiliser des SLOT particulier, mais comme vous le voyer, ca ne marche pas
comment faire pour pouvoir faire fonctionner le prog(la fonction mainwindow::about() n'est q'une boite de texte)
j'attent vos reponse avec impatience !

PS : je suis en vacance 7 semaine, alors si je ne repond pas c'est normal(vous avez deja vu une connection internet sur un bateau vous ????