Bonjour,

j'ai le livre "Qt4 et C++, programmation d'interfaces GUI", et un des premiers exemple ne marche pas chez moi:

le livre expose un programme de tableur(enfin je crois, je n'en suis qu'au début).
La première QDialog est créée entièrement par du code, mais pas la seconde, qui est créée avec le RAD d'eclipse; peu importe ce qu'elle fait (affichage d'une boîte de dialogue pour aller à une autre cellule; il est plus intéressant de savoir que la classe créée à partir de gotocelldialog.ui, qui s'appelle Ui::gotocelldialog, sert dans un héritage double, la deuxième parente étant QDialog(voir la ligne marquée d'une flèche). La classe fille, GoToCellDialog, devrait posséder une méthode show(), or il semble que le compilateur ne la trouve pas.

mis en application cela donne:

-fichier ui_gotocelldialog.h(seules les 10 dernières lignes sont importantes)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
 
/********************************************************************************
** Form generated from reading ui file 'gotocelldialog.ui'
**
** Created: Fri 13. Jun 19:43:45 2008
**      by: Qt User Interface Compiler version 4.4.0
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
 
#ifndef UI_GOTOCELLDIALOG_H
#define UI_GOTOCELLDIALOG_H
 
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
 
QT_BEGIN_NAMESPACE
 
class Ui_GoToCellDialog
{
public:
    QVBoxLayout *verticalLayout;
    QHBoxLayout *horizontalLayout_2;
    QLabel *label;
    QLineEdit *lineEdit;
    QHBoxLayout *horizontalLayout;
    QSpacerItem *horizontalSpacer;
    QPushButton *okButton;
    QPushButton *cancelButton;
 
    void setupUi(QWidget *GoToCellDialog)
    {
    if (GoToCellDialog->objectName().isEmpty())
        GoToCellDialog->setObjectName(QString::fromUtf8("GoToCellDialog"));
    GoToCellDialog->resize(224, 73);
    verticalLayout = new QVBoxLayout(GoToCellDialog);
    verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
    horizontalLayout_2 = new QHBoxLayout();
    horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
    label = new QLabel(GoToCellDialog);
    label->setObjectName(QString::fromUtf8("label"));
 
    horizontalLayout_2->addWidget(label);
 
    lineEdit = new QLineEdit(GoToCellDialog);
    lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
 
    horizontalLayout_2->addWidget(lineEdit);
 
 
    verticalLayout->addLayout(horizontalLayout_2);
 
    horizontalLayout = new QHBoxLayout();
    horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
    horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
 
    horizontalLayout->addItem(horizontalSpacer);
 
    okButton = new QPushButton(GoToCellDialog);
    okButton->setObjectName(QString::fromUtf8("okButton"));
    okButton->setEnabled(false);
    okButton->setDefault(true);
 
    horizontalLayout->addWidget(okButton);
 
    cancelButton = new QPushButton(GoToCellDialog);
    cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
 
    horizontalLayout->addWidget(cancelButton);
 
 
    verticalLayout->addLayout(horizontalLayout);
 
    label->setBuddy(lineEdit);
    QWidget::setTabOrder(lineEdit, okButton);
    QWidget::setTabOrder(okButton, cancelButton);
 
    retranslateUi(GoToCellDialog);
 
    QMetaObject::connectSlotsByName(GoToCellDialog);
    } // setupUi
 
    void retranslateUi(QWidget *GoToCellDialog)
    {
    GoToCellDialog->setWindowTitle(QApplication::translate("GoToCellDialog", "go to cell", 0, QApplication::UnicodeUTF8));
    label->setText(QApplication::translate("GoToCellDialog", "&Cell location", 0, QApplication::UnicodeUTF8));
    okButton->setText(QApplication::translate("GoToCellDialog", "OK", 0, QApplication::UnicodeUTF8));
    cancelButton->setText(QApplication::translate("GoToCellDialog", "Cancel", 0, QApplication::UnicodeUTF8));
    Q_UNUSED(GoToCellDialog);
    } // retranslateUi
 
};
 
namespace Ui {
    class GoToCellDialog: public Ui_GoToCellDialog {};   // <-----------
} // namespace Ui
 
QT_END_NAMESPACE
 
#endif // UI_GOTOCELLDIALOG_H
fichier gotocelldialog.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
 
#ifndef GOTOCELLDIALOG_H_
#define GOTOCELLDIALOG_H_
 
#include <QDialog>
#include "ui_gotocelldialog.h"
 
class GoToCellDialog : public QDialog,public Ui::GoToCellDialog
{
	Q_OBJECT
 
public:
	GoToCellDialog (QWidget* parent=0);
 
private slots:
	void on_lineEdit_textChanged();
 
};
 
 
#endif /*GOTOCELLDIALOG_H_*/
fichier gotocelldialog.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
 
#include <QtGui>
#include <QDialog>
#include "gotocelldialog.h"
 
GoToCellDialog::GoToCellDialog(QWidget* parent) : QDialog(parent)
	{
	setupUi(this);
	QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
 
	lineEdit->setValidator(new QRegExpValidator(regExp,this));
 
	connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
	connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
 
	}
 
void GoToCellDialog::on_lineEdit_textChanged()
{
	okButton->setEnabled(lineEdit->hasAcceptableInput());
 
}
enfin; fichier main.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
 
#include <QtGui>
#include <QApplication>
#include <QDialog>
//#include "finddialog.h"
#include "ui_gotocelldialog.h"
 
 
int main(int argc,char* argv[])
{
	QApplication app(argc,argv);
	//FindDialog* dialog=new FindDialog;
	//dialog->show();
 
	//Ui::GoToCellDialog ui;
	//QDialog* dialog=new QDialog;
	//ui.setupUi(dialog);
	//dialog->show();
 
	GoToCellDialog* dialog; //=new GoToCellDialog; <--  <--
	dialog->show();
 
	return app.exec();




et l'erreur est:

"dialog undeclared(first use in this function)" et une deuxième:
" 'GoToCellDilaog' undeclared" (first use in this function), à la ligne marquée de 2 flèches.

J'ai cherché comment résoudre ce problème mais sans succès, si il faut déclarer la variable dialog ailleurs je ne vois pas où.

lolveley.