Bonsoir,

J'essaie de me convertir au C++ et donc je débute en C++ et Qt.

Je voudrais essayer de comprendre comment afficher les items d'un QComboBox dans une fenêtre de dialogue avec les connecteurs SIGNAL/SLOT.

Voici mon fichier Tcombobox.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
#ifndef TCOMBOBOX_H
#define TCOMBOBOX_H
    #include <QApplication>
    #include <QWidget>
    #include <QDialog>
    #include <QStringList>
    #include <QList>
 
    namespace Ui { class TcomboBox; }
 
    class TcomboBox : public QDialog
    {
        Q_OBJECT
 
    public:
        explicit TcomboBox(QWidget *parent = nullptr);
        void AjouterItems();
 
 
        ~TcomboBox();
 
    private:
        Ui::TcomboBox *ui;
        QList<QString> *vListe;
    };
 
#endif // TCOMBOBOX_H
et voici mon fichier Tcombobox.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
#include "tcombobox.h"
#include "ui_tcombobox.h"
 
TcomboBox::TcomboBox(QWidget *parent) : QDialog(parent),
 
    ui(new Ui::TcomboBox)
{
    ui->setupUi(this);
 
    // Ajout d'Items 'en dur'
        ui->CboTravail->addItem("Session de travail");
        ui->CboTravail->addItem("Session de Restauration");
 
    // Ajout d'Items avec QList dans le constructeur
        QList<QString> LListe;
        int i;
        for (i = 2000; i < 2010; ++i)
        { LListe.append(QString::number(i) + '/' + QString::number(i+1)); };
        ui->CboList->addItems(LListe);
 
    // Ajout d'Items avec QList à partir d'une fonction
        vListe = new QList<QString>;
        ui->CboSession->showPopup();
 
    // Connection aux fonctions
 
        // Connection du Bouton "BtnQuitter"
        QObject::connect(ui->BtnQuitter,SIGNAL(clicked()),this,SLOT(close()));
 
        // Connection du ComboBox "CboSession"
        QObject::connect(ui->CboSession,SIGNAL(currentText()),this,SLOT(AjouterItems()));
}
 
void TcomboBox::AjouterItems()
{
    for (int i = 2000; i < 2010; ++i)
    {
        vListe->append(QString::number(i)+'/'+QString::number(i+1));//vListe est déclaré dans Tcombobox en private
    };
}
 
TcomboBox::~TcomboBox()
{ delete ui; }
et mon fichier Tcombobox.ui
Code xml : 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
110
111
112
113
114
115
116
117
118
119
120
121
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>TcomboBox</class>
 <widget class="QDialog" name="TcomboBox">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>505</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Teste Utilistaion QComboBox</string>
  </property>
  <widget class="QLabel" name="LblTitre">
   <property name="geometry">
    <rect>
     <x>140</x>
     <y>20</y>
     <width>220</width>
     <height>22</height>
    </rect>
   </property>
   <property name="palette">
    <palette>
     <active>
      <colorrole role="WindowText">
       <brush brushstyle="SolidPattern">
        <color alpha="255">
         <red>0</red>
         <green>0</green>
         <blue>255</blue>
        </color>
       </brush>
      </colorrole>
     </active>
     <inactive>
      <colorrole role="WindowText">
       <brush brushstyle="SolidPattern">
        <color alpha="255">
         <red>0</red>
         <green>0</green>
         <blue>0</blue>
        </color>
       </brush>
      </colorrole>
     </inactive>
     <disabled>
      <colorrole role="WindowText">
       <brush brushstyle="SolidPattern">
        <color alpha="255">
         <red>120</red>
         <green>120</green>
         <blue>120</blue>
        </color>
       </brush>
      </colorrole>
     </disabled>
    </palette>
   </property>
   <property name="font">
    <font>
     <pointsize>12</pointsize>
     <bold>true</bold>
    </font>
   </property>
   <property name="text">
    <string>Utilisation des ComboBox</string>
   </property>
   <property name="alignment">
    <set>Qt::AlignCenter</set>
   </property>
  </widget>
  <widget class="QComboBox" name="CboTravail">
   <property name="geometry">
    <rect>
     <x>50</x>
     <y>80</y>
     <width>151</width>
     <height>22</height>
    </rect>
   </property>
  </widget>
  <widget class="QPushButton" name="BtnQuitter">
   <property name="geometry">
    <rect>
     <x>420</x>
     <y>260</y>
     <width>75</width>
     <height>24</height>
    </rect>
   </property>
   <property name="text">
    <string>Quitter</string>
   </property>
  </widget>
  <widget class="QComboBox" name="CboList">
   <property name="geometry">
    <rect>
     <x>300</x>
     <y>80</y>
     <width>81</width>
     <height>22</height>
    </rect>
   </property>
  </widget>
  <widget class="QComboBox" name="CboSession">
   <property name="geometry">
    <rect>
     <x>180</x>
     <y>150</y>
     <width>131</width>
     <height>22</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

Mon problème est que le comboBox "CboSession" n'affiche rien.

Et dans l'onglet "Application output" de l'IDE j'ai le message suivant :

No such signal QComboBox::currentText() in ..\Bourse\bourse.cpp:31
Ma question : Comment afficher les items de CboSession sur la forme en utilisant SIGNAL/SLOT qu’apparemment je ne maitrise pas.

Merci pour m'aider à comprendre l'utilisation de "SIGNAL / SLOT".
Bonne soirée.