IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Qt Discussion :

question simple a propos de QDialog


Sujet :

Qt

  1. #1
    Membre averti Avatar de elmcherqui
    Profil pro
    Inscrit en
    Février 2008
    Messages
    281
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : Maroc

    Informations forums :
    Inscription : Février 2008
    Messages : 281
    Points : 382
    Points
    382
    Par défaut question simple a propos de QDialog
    bonjour je suis entrain de creer un petit programme qui comporte 2fenetre donc 2classes .
    la premiere derive de QWidget et c'est la fenetre principale elle comporte plein de widget + un bouton "votre nom" qui ouvre la deuxieme fenetre qui derive de QDialog qui comporte un QLineEdit pour entrer un nom + un bouton ok relie a accept() et un bouton cancel relie a reject() ;

    ma question est comment recuperer l'enumeration Accepted ou Rejected suivant le bout0on que j'ai clique ?

    Merci

  2. #2
    Membre expert

    Avatar de IrmatDen
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 727
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 727
    Points : 3 266
    Points
    3 266
    Par défaut
    Salut,

    En utilisant QDialog::result().

  3. #3
    Membre averti Avatar de elmcherqui
    Profil pro
    Inscrit en
    Février 2008
    Messages
    281
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : Maroc

    Informations forums :
    Inscription : Février 2008
    Messages : 281
    Points : 382
    Points
    382
    Par défaut
    Citation Envoyé par IrmatDen Voir le message
    Salut,

    En utilisant QDialog::result().
    merci d'avoir repondu mais je connais cette fonction , le probleme est que je ne sais pas ou la mettre .

    voila mon code qui se compose de 3feuilles .

    main.cpp / MaFenetre.h /MaFenetre.cpp

    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
     
    #include <QApplication>
    #include<QDialog>
     
    #include"MaFenetre.h"
     
    int main(int argc, char* argv[])
    {
        QApplication app(argc, argv);
        Mainwindow window;
        window.show();
     
     
        return app.exec();
    }
    MaFenetre.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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
     
     
    #ifndef MAFENETRE_H_INCLUDED
    #define MAFENETRE_H_INCLUDED
     
    #include<QWidget>
    #include<QDialog>
    #include<QLabel>
    #include<QPushButton>
    #include<QLineEdit>
     
    class MaFenetre : public QDialog
    {
        Q_OBJECT
     
    public:
        MaFenetre(QWidget *parent=0);
        QString getText(){line->text();}
     
     
     
    private :
        QPushButton   * okbutton;
        QPushButton   * cancelbutton;
        QLabel        * label;
        QLineEdit     * line;
     
     
    };
     
    class Mainwindow :public QWidget
    {
        Q_OBJECT
    public :
        Mainwindow();
     
    public slots:
        void ouvrire_dialog();
     
    private:
        QPushButton *quitterbutton;
        QPushButton *avoirnom;
        QPushButton *aproposbutton;
        QLineEdit   *main_line;
        MaFenetre    fenetre;
        int          resultat;
     
    };
     
     
    #endif // MAFENETRE_H_INCLUDED

    MaFenetre.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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
     
     
    #include<QtGui>
     
    #include"MaFenetre.h"
     
    MaFenetre::MaFenetre(QWidget *parent):QDialog(parent)
    {
        label = new QLabel("&Votre nom please");
        line = new QLineEdit;
        label->setBuddy(line);
     
        okbutton = new QPushButton("&Ok");
        cancelbutton = new QPushButton("&Cancel");
     
        QHBoxLayout *horilayout_haut = new QHBoxLayout;
        horilayout_haut->addWidget(label);
        horilayout_haut->addWidget(line);
     
        QHBoxLayout *horilayout_bas = new QHBoxLayout;
        horilayout_bas->addWidget(okbutton);
        horilayout_bas->addWidget(cancelbutton);
     
        QVBoxLayout *layout = new QVBoxLayout;
        layout->addLayout(horilayout_haut);
        layout->addLayout(horilayout_bas);
        setLayout(layout);
     
        /**ordre tabulation**/
        setTabOrder(label,okbutton);
        setTabOrder(okbutton,cancelbutton);
     
     
     
        /**CoOonexion**/
        QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(accept()));
        QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject()));
     
     
    }
     
    Mainwindow::Mainwindow():QWidget()
    {
        quitterbutton = new QPushButton("&Quitter");
        aproposbutton = new QPushButton("&Apropos");
        avoirnom      = new QPushButton("&Donne le nom");
        main_line     = new QLineEdit;
     
        QHBoxLayout *hori_layout = new QHBoxLayout;
        hori_layout->addWidget(avoirnom);
        hori_layout->addWidget(main_line);
     
        QVBoxLayout *verti_layout = new QVBoxLayout;
        verti_layout->addWidget(aproposbutton);
        verti_layout->addWidget(quitterbutton);
     
        QVBoxLayout *mainlayout = new QVBoxLayout;
        mainlayout->addLayout(hori_layout);
        mainlayout->addLayout(verti_layout);
        setLayout(mainlayout);
     
        /**CoOonection**/
        QObject::connect(aproposbutton,SIGNAL(clicked()),qApp,SLOT(aboutQt()));
        QObject::connect(quitterbutton,SIGNAL(clicked()),qApp,SLOT(quit()));
        QObject::connect(avoirnom,SIGNAL(clicked()),this,SLOT(ouvrire_dialog()));
     
    }
    void Mainwindow::ouvrire_dialog()
    {   resultat = 0;
        resultat = fenetre.exec();       /**le probleme se situe ici **/
        QString nom = fenetre.getText();/*je ne sais pas comment gerer**/
         if(resultat) {                           /*la reponse*/
            main_line->setText( nom );
        }
     
     
    }
    sa compile mais sa me met une erreur windows . le probleme vien du slot ouvrir_dialog .

    je ne sais pas comment prendre le texte de la boite de dialog si lutilisateur clique sur ok je le met sur la fenetre principale sinon j'ecrit NULL .

    voila merci de m'aider

  4. #4
    Membre expert

    Avatar de IrmatDen
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 727
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 727
    Points : 3 266
    Points
    3 266
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    void Mainwindow::ouvrire_dialog()
    {
        if(fenetre.exec() == QDialog::Accepted)
        {
            QString nom = fenetre.getText();
            main_line->setText( nom );
        }
    }
    Et pas la peine de mettre QObject:: avant chaque connect puisque tes classes dérivent toutes 2 à un certain niveau de QObject.

    PS: tu ferais mieux aussi de faire de ton instance de Fenetre un pointeur, l'instance en question étant fille de MainWindow pour ne pas avoir à la supprimer toi-même.

  5. #5
    Membre averti Avatar de elmcherqui
    Profil pro
    Inscrit en
    Février 2008
    Messages
    281
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : Maroc

    Informations forums :
    Inscription : Février 2008
    Messages : 281
    Points : 382
    Points
    382
    Par défaut
    merci c'est ce que je voulais savoir

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Question simple à propos des ports
    Par foufar2009 dans le forum Développement
    Réponses: 1
    Dernier message: 06/07/2009, 17h42
  2. Question simple à propos des USE CASE
    Par foufar2009 dans le forum Cas d'utilisation
    Réponses: 3
    Dernier message: 01/06/2009, 15h51
  3. Réponses: 12
    Dernier message: 29/04/2008, 00h42
  4. [LG]Choix du pascal ou autre ? Questions simples...
    Par vlacq dans le forum Langage
    Réponses: 5
    Dernier message: 30/01/2004, 23h42
  5. Question simple sur les threads :)
    Par momox dans le forum C++Builder
    Réponses: 2
    Dernier message: 15/06/2003, 04h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo