Bonjour,
je débute en C++, j'essaye donc de mettre en application ce que j’apprends sur les sites mais je bute sur un probleme depuis plusieurs jours.
Je lis des valeurs dans un fichier ini pour venir modifier position et taille fenêtre principal en passant par une fonction, l'appel a cette fonction marche tres bien quand je l'appelle dans le mainwindow.cpp ligne 19 mais ne fonctionne plus dans le sous_prog.cpp ligne 57
D:\hubic\Qt\Fenetre\testFenetre\sous_prog.cpp:57: erreur : cannot call member function 'void MainWindow::parametreFenetre(int, int, int, int)' without object
un peu d'aide et d'explications serait le bienvenue
merci d'avance
mainwindow.h
sous_prog.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 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); public slots: void parametreFenetre(int posX, int posY, int taiX, int taiY); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
main.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 #ifndef SOUS_PROG_H #define SOUS_PROG_H #include <Qstring> #include <string> using namespace std; void chargeIni(); // Chargement fichier Ini #endif // SOUS_PROG_H
mainwindow.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
sous_prog.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 #include "QObject" #include "mainwindow.h" #include "ui_mainwindow.h" #include "sous_prog.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->label->setText(QCoreApplication::applicationDirPath()+"/infos.ini"); chargeIni(); parametreFenetre(50,50,320,200); } MainWindow::~MainWindow() { delete ui; } void MainWindow::parametreFenetre(int posX, int posY, int taiX, int taiY) { this->setGeometry(posX , posY , taiX , taiY ); }
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 #include "QObject" #include "QCoreApplication" #include "QFileInfo" #include "QMessageBox" #include "QSettings" #include "sous_prog.h" #include "mainwindow.h" #include "sous_prog.h" #include <QBool> #include <string> #include <sstream> using namespace std; // ------------------------------------------------------------------------------------------------ // ###################### // # Charge Fichier Ini # // ###################### void chargeIni() { QString cheminIni = (QCoreApplication::applicationDirPath()+"/infos.ini"); if(!QFileInfo(cheminIni).exists()) { // Fichier INI inexistant --------------------------------------------------------------- QMessageBox::information(NULL,"erreur","fichier INI non trouvé"); // Nouveau fichier ------------------------------------------------------------------------ QSettings settings(cheminIni, QSettings::IniFormat); settings.beginGroup("Fenetre"); settings.beginGroup("Principal"); settings.setValue("posX",68); settings.setValue("posY",37); settings.setValue("taiX",800); settings.setValue("taiY",590); settings.endGroup(); settings.endGroup(); QMessageBox::information(NULL,"Ini","Fichier crée"); } else {// Fichier INI trouvé -------------------------------------------------------------------- // Ouverture du fichier INI --------------------------------------------------------------- QSettings settings(cheminIni, QSettings::IniFormat); settings.beginGroup("Fenetre"); // Ouverture du groupe 'Fenetre' settings.beginGroup("Principal"); // Ouverture du groupe 'Principal' int posX = settings.value("posX",8).toInt(); int posY = settings.value("posY",8).toInt(); int taiX = settings.value("taiX",400).toInt(); int taiY = settings.value("taiY",200).toInt(); settings.endGroup(); // fermeture group 'Principal' settings.endGroup(); // fermeture group 'Fenetre' MainWindow::parametreFenetre(posX, posY, taiX, taiY); QMessageBox::information(NULL,"Ini","Trouvé"); } }
Partager