Bonjour, [c++ et QT]
Je tente de connecter plusieurs boutons dans mon exemple ici deux mais aura pour but d'en connecter plusieurs autres. Cependant je reçois un message d'erreur.
1 2 3 4 5 6 7 8 9 10 | C:\Users\Black\Documents\Dev\QT dev\OC_LILI_BOX\fenetre.cpp:20: erreur : C2679: '=' binaireÿ: aucun op‚rateur trouv‚ qui accepte un op‚rande de partie droite de type 'QString *' (ou il n'existe pas de conversion acceptable) C:\Dev Installation\QT\5.5\msvc2013_64\include\QtCore/qstring.h(757): peut ˆtre 'QString &QString::operator =(const QString::Null &)' C:\Dev Installation\QT\5.5\msvc2013_64\include\QtCore/qstring.h(659): ou 'QString &QString::operator =(char)' C:\Dev Installation\QT\5.5\msvc2013_64\include\QtCore/qstring.h(657): ou 'QString &QString::operator =(const QByteArray &)' C:\Dev Installation\QT\5.5\msvc2013_64\include\QtCore/qstring.h(655): ou 'QString &QString::operator =(const char *)' C:\Dev Installation\QT\5.5\msvc2013_64\include\QtCore/qstring.h(225): ou 'QString &QString::operator =(QString &&) throw()' C:\Dev Installation\QT\5.5\msvc2013_64\include\QtCore/qstring.h(222): ou 'QString &QString::operator =(QLatin1String)' C:\Dev Installation\QT\5.5\msvc2013_64\include\QtCore/qstring.h(221): ou 'QString &QString::operator =(const QString &) throw()' C:\Dev Installation\QT\5.5\msvc2013_64\include\QtCore/qstring.h(220): ou 'QString &QString::operator =(QChar)' lors de la tentative de mise en correspondance de la liste des arguments '(QString, QString *)' |
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 | #include <QApplication> #include "fenetre.h" int main(int argc, char *argv[]) { QApplication a(argc,argv); fenetre fenetres; fenetres.show(); return a.exec(); } |
fenetre.cpp
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 | #include "fenetre.h" fenetre::fenetre() : QWidget() { //fixation de la taille et le nom de la fenetre setFixedSize(300,300); setWindowTitle("test"); //Création des Bouton 1 et 2 m_QPushbutton = new QPushButton("bouton 1"); m_QPushButton2 = new QPushButton("bouton 2"); //initialisation des label 0 (de base) et des deux label de comparateur m_label10 = new QLabel("label de base"); m_label1 = new QLabel("Label un"); m_label2 = new QLabel("Label 2"); //initialisation des Qstring à mettre dans le label 0 m_stringUn = new QString("Clique 1"); m_stringDeux = new QString("Clique 2"); m_QHBox_Layout = new QHBoxLayout(this); m_QHBox_Layout->addWidget(m_QPushbutton); m_QHBox_Layout->addWidget(m_QPushButton2); m_QHBox_Layout->addWidget(m_label10); connect(m_QPushbutton, &QPushButton::clicked,[=]() { fenetre::setText(m_label1); }); connect(m_QPushButton2, &QPushButton::clicked,[=]() { fenetre::setText(m_label2); } ) ; } void fenetre::setText(QLabel *from) { m_label10->clear(); if(from == m_label1) { m_label10->setText(m_stringUn); } if(from == m_label2) { m_label10->setText(m_stringDeux); } } |
fenetre.h
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 | #ifndef FENETRE #define FENETRE #include <QWidget> #include <QPushButton> #include <QLabel> #include <QHBoxLayout> #include <QObject> #include <QLayout> #include <QString> class fenetre : public QWidget { Q_OBJECT public: fenetre(); void fenetre::setText(QLabel *from); private: QWidget *m_QWidget; QPushButton *m_QPushbutton; QPushButton *m_QPushButton2; QLabel *m_label10; QLabel *m_label1; QLabel *m_label2; QHBoxLayout *m_QHBox_Layout; QLayout *m_Q_layout; QString *m_stringZero; QString m_stringUn; QString m_stringDeux; }; #endif // FENETRE |
+0
-0