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

Discussion :

Fuite de mémoire

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut Fuite de mémoire
    Bonsoir tout le monde.

    Je me permet de faire appel à vos lumières car je sèche sur un problème.

    Il y a de ça plusieurs mois, je me suis lancé dans l'apprentissage du C++ et suis donc passé par Qt et la SFML.

    Dans le but de m'améliorer et surtout de manipuler ce que j'ai appris je me suis lancé dans le codage d'un jeu vidéo (via SFML), un Zelda like, que j'ai mis entre parenthèse pour créer une application pour mon travail. J'avais alors demandé un peu d'aide ici http://www.developpez.net/forums/d15...besoin-d-aide/

    Travaillant dans un magasin, mon application a pour but d'aider les clients à trouver les cartouches d'encre correspondant à leurs imprimantes en sélectionnant la marque, puis encre ou laser, puis la famille et enfin le modèle.

    Mon application est maintenant terminée (enfin la v1) et est fonctionnelle. J'ai codé cette application via Qt 5.4.1.

    J'ai cependant un problème de fuite de mémoire...

    Ma "v1" est constituée, au niveau code, d'un "joli bordel".

    Pour me simplifier le travail pour les ajouts (modèles d'imprimantes...) j'ai une base de données sous forme d'un fichier .txt et mon application qui va lire les informations correspondant aux boutons du modèle cliqué.

    Mon application en elle même est composée :
    - d'une page principale de sélection de marques qui est fixe et ne doit pas être fermée
    - d'une fenêtre de sélection de type (encre ou laser) - par marque (qui se ferme lors de l'ouverture de la suivante ou pour revenir à la page principale)
    - d'une fenêtre de sélection de famille - par type et par marque (qui se ferme lors de l'ouverture de la suivante ou pour revenir à la page principale)
    - d'une fenêtre de sélection de modèle - par famille, type et marque (qui se ferme lors de l'ouverture de la suivante ou pour revenir à la page principale)
    - et enfin d'une fenêtre finale qui affiche les références des cartouches - cette page est commune à tous les modèles (qui se ferme lors de l'ouverture de la suivante ou pour revenir à la page principale)

    Donc : 6 marques, 2 type par marque, plusieurs famille par type, quelques milliers de modèles en tout et une page finale... ça donne le main.cpp + 175 ".cpp" + 175 ".h" (d'où le "joli bordel"... sans compter les quelques images pour que ça soit joli et la base de données .txt).

    Quand j'exécute mon application elle utilise environ 440 Mo de mémoire vive à peine ouverte et à chaque fois que je clique sur un bouton (pour ouvrir la page suivante) cela me rajoute 5 Mo à chaque fois seulement au 1er lancement de chaque page (exemple, si j'ouvre 10 fois la page de la marque 1, je n'ai qu'une fois 5 Mo ajouté).

    Voilà mon problème...

    Et vu que c'est une application qui tournera en permanence tout au long de la journée, cela va vite saturer la mémoire vive...

    Auriez-vous une idée pour régler mon problème ?

    Par avance merci

    P.S. : le code arrive dans mon post suivant pour faciliter la lecture

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut Mon code (enfin pas tout car très long)
    Je ne vais pas mettre tout mon code, car très long, mais le code du main et de chaque page pour le chemin depuis le choix d'une marque, d'un type (encre), d'une famille, d'un modèle et enfin la page affichant les références.

    Voici le 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
    #include <QApplication>
     
    #include "MainWindow.h"
     
     
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
     
        MainWindow window;
        window.show();
     
        return app.exec();
    }
    Ma fenêtre principale (choix de marque) :
    MainWindow.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
    #ifndef MAINWINDOW
    #define MAINWINDOW
     
    #include <QtWidgets>
    #include "Init.h"
    #include "BrotherTypeWindow.h"
    #include "CanonTypeWindow.h"
    #include "EpsonTypeWindow.h"
    #include "HPTypeWindow.h"
    #include "LexmarkTypeWindow.h"
    #include "SamsungTypeWindow.h"
     
    class MainWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        MainWindow();
     
        private slots:
        void runBrother();
        void runCanon();
        void runEpson();
        void runHp();
        void runLexmark();
        void runSamsung();
     
        private:
        QPushButton *brotherButton;
        QPushButton *canonButton;
        QPushButton *epsonButton;
        QPushButton *hpButton;
        QPushButton *lexmarkButton;
        QPushButton *samsungButton;
     
        QPushButton *logo;
     
        BrotherTypeWindow brotherTypeWindow;
        CanonTypeWindow canonTypeWindow;
        EpsonTypeWindow epsonTypeWindow;
        HPTypeWindow hpTypeWindow;
        LexmarkTypeWindow lexmarkTypeWindow;
        SamsungTypeWindow samsungTypeWindow;
     
        void Button();
        void Slots();
    };
     
    #endif // MAINWINDOW
    MainWindow.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
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    #include "MainWindow.h"
     
    MainWindow::MainWindow() : QWidget()
    {
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Fenêtre Principale"));
     
        Button();
     
        Slots();
    }
     
    //############### Private functions ###############
    void MainWindow::Button()
    {
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        brotherButton = new QPushButton(QIcon("pictures/brother.png"), "", this);
        brotherButton->setGeometry(Init::MARK_COL_1, Init::MARK_LIN_1, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        brotherButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        brotherButton->setFlat(true);
     
        canonButton = new QPushButton(QIcon("pictures/canon.png"), "", this);
        canonButton->setGeometry(Init::MARK_COL_2, Init::MARK_LIN_1, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        canonButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        canonButton->setFlat(true);
     
        epsonButton = new QPushButton(QIcon("pictures/epson.png"), "", this);
        epsonButton->setGeometry(Init::MARK_COL_1, Init::MARK_LIN_2, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        epsonButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        epsonButton->setFlat(true);
     
        hpButton = new QPushButton(QIcon("pictures/hp.png"), "", this);
        hpButton->setGeometry(Init::MARK_COL_2, Init::MARK_LIN_2, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        hpButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        hpButton->setFlat(true);
     
        lexmarkButton = new QPushButton(QIcon("pictures/lexmark.png"), "", this);
        lexmarkButton->setGeometry(Init::MARK_COL_1, Init::MARK_LIN_3, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        lexmarkButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        lexmarkButton->setFlat(true);
     
        samsungButton = new QPushButton(QIcon("pictures/samsung.png"), "", this);
        samsungButton->setGeometry(Init::MARK_COL_2, Init::MARK_LIN_3, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        samsungButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        samsungButton->setFlat(true);
    }
     
    void MainWindow::Slots()
    {
        connect(brotherButton, SIGNAL(clicked()), this, SLOT(runBrother()));
        connect(canonButton, SIGNAL(clicked()), this, SLOT(runCanon()));
        connect(epsonButton, SIGNAL(clicked()), this, SLOT(runEpson()));
        connect(hpButton, SIGNAL(clicked()), this, SLOT(runHp()));
        connect(lexmarkButton, SIGNAL(clicked()), this, SLOT(runLexmark()));
        connect(samsungButton, SIGNAL(clicked()), this, SLOT(runSamsung()));
    }
     
    //############### Private slots ###############
    void MainWindow::runBrother()
    {
        brotherTypeWindow.show();
    }
     
    void MainWindow::runCanon()
    {
        canonTypeWindow.show();
    }
     
    void MainWindow::runEpson()
    {
        epsonTypeWindow.show();
    }
     
    void MainWindow::runHp()
    {
        hpTypeWindow.show();
    }
     
    void MainWindow::runLexmark()
    {
        lexmarkTypeWindow.show();
    }
     
    void MainWindow::runSamsung()
    {
        samsungTypeWindow.show();
    }
    La page du choix de type pour Brother :
    BrotherTypeWindow.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
    #ifndef BROTHERTYPEWINDOW
    #define BROTHERTYPEWINDOW
     
    #include <QtWidgets>
    #include "Init.h"
    #include "BrotherHomeWindow.h"
    #include "BrotherLaserHomeWindow.h"
     
    class BrotherTypeWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        BrotherTypeWindow();
     
        private slots:
        void RunInk();
        void RunLaser();
     
        private:
        QPushButton *exitButton;
        QPushButton *type1Button;
        QPushButton *type2Button;
     
        QPushButton *logo;
        QPushButton *markPic;
     
        BrotherHomeWindow brotherHomeWindow;
        BrotherLaserHomeWindow brotherLaserHomeWindow;
     
        void Button();
        void Slots();
    };
     
    #endif // BROTHERTYPEWINDOW
    BrotherTypeWindow.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
    #include "BrotherTypeWindow.h"
     
    BrotherTypeWindow::BrotherTypeWindow() : QWidget()
    {
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Brother"));
     
        Button();
        Slots();
    }
     
    //############### Private functions ###############
    void BrotherTypeWindow::Button()
    {
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        markPic = new QPushButton(QIcon("pictures/brother.png"), "", this);
        markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->setFlat(true);
     
        type1Button = new QPushButton("Jet d'encre", this);
        type1Button->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_1, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        type1Button->setFont(Init::FONT1);
     
        type2Button = new QPushButton("Laser", this);
        type2Button->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_2, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        type2Button->setFont(Init::FONT1);
     
        exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
        exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
    }
     
    void BrotherTypeWindow::Slots()
    {
        connect(exitButton, SIGNAL(clicked()), this, SLOT(close()));
        connect(type1Button, SIGNAL(clicked()), this, SLOT(RunInk()));
        connect(type2Button, SIGNAL(clicked()), this, SLOT(RunLaser()));
    }
     
    //############### Private slots ###############
    void BrotherTypeWindow::RunInk()
    {
        close();
        brotherHomeWindow.show();
    }
     
    void BrotherTypeWindow::RunLaser()
    {
        close();
        brotherLaserHomeWindow.show();
    }
    La page du choix de famille pour brother -> encre
    BrotherHomeWindow.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
    #ifndef BROTHERHOMEWINDOW
    #define BROTHERHOMEWINDOW
     
    #include <QtWidgets>
    #include "Init.h"
    #include "BrotherDCPSeriesWindow.h"
    #include "BrotherMFCSeriesWindow.h"
    #include "BrotherFAXSeriesWindow.h"
     
    class BrotherHomeWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        BrotherHomeWindow();
     
        private slots:
        void RunDCP();
        void RunFAX();
        void RunMFC();
     
        private:
        QPushButton *exitButton;
        QPushButton *series1Button;
        QPushButton *series2Button;
        QPushButton *series3Button;
     
        QPushButton *logo;
        QPushButton *markPic;
     
        BrotherDCPSeriesWindow brotherDCPSeriesWindow;
        BrotherFAXSeriesWindow brotherFAXSeriesWindow;
        BrotherMFCSeriesWindow brotherMFCSeriesWindow;
     
        void Button();
        void Slots();
    };
     
    #endif // BROTHERHOMEWINDOW
    BrotherHomeWindow.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
    #include "BrotherHomeWindow.h"
     
    BrotherHomeWindow::BrotherHomeWindow() : QWidget()
    {
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Brother"));
     
        Button();
        Slots();
    }
     
    //############### Private functions ###############
    void BrotherHomeWindow::Button()
    {
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        markPic = new QPushButton(QIcon("pictures/brother.png"), "", this);
        markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->setFlat(true);
     
        series1Button = new QPushButton;
        series1Button->setGeometry(Init::HOME_COL_1, Init::HOME_LIN_1, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series1Button->setText("Série DCP");
        series1Button->setFont(Init::FONT6);
        series1Button->setParent(this);
     
        series2Button = new QPushButton;
        series2Button->setGeometry(Init::HOME_COL_2, Init::HOME_LIN_1, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series2Button->setText("Série FAX");
        series2Button->setFont(Init::FONT6);
        series2Button->setParent(this);
     
        series3Button = new QPushButton;
        series3Button->setGeometry(Init::HOME_COL_1, Init::HOME_LIN_2, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series3Button->setText("Série MFC");
        series3Button->setFont(Init::FONT6);
        series3Button->setParent(this);
     
        exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
        exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
    }
     
    void BrotherHomeWindow::Slots()
    {
        connect(exitButton, SIGNAL(clicked()), this, SLOT(close()));
        connect(series1Button, SIGNAL(clicked()), this, SLOT(RunDCP()));
        connect(series2Button, SIGNAL(clicked()), this, SLOT(RunFAX()));
        connect(series3Button, SIGNAL(clicked()), this, SLOT(RunMFC()));
    }
     
    //############### Private slots ###############
    void BrotherHomeWindow::RunDCP()
    {
        close();
        brotherDCPSeriesWindow.show();
    }
     
    void BrotherHomeWindow::RunFAX()
    {
        close();
        brotherFAXSeriesWindow.show();
    }
     
    void BrotherHomeWindow::RunMFC()
    {
        close();
        brotherMFCSeriesWindow.show();
    }
    La page de sélection du modèle pour la première famille :
    BrotherDCPSeriesWindow.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
    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
    #ifndef BROTHERDCPSERIESWINDOW
    #define BROTHERDCPSERIESWINDOW
     
    #include <QtWidgets>
    #include "Init.h"
    #include "FinalWindow.h"
     
    class BrotherDCPSeriesWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        BrotherDCPSeriesWindow();
     
        private slots:
        void NextClicked();
        void PreviousClicked();
        void Button1Clicked();
        void Button2Clicked();
        void Button3Clicked();
        void Button4Clicked();
        void Button5Clicked();
        void Button6Clicked();
        void Button7Clicked();
        void Button8Clicked();
        void Button9Clicked();
        void Button10Clicked();
        void Button11Clicked();
        void Button12Clicked();
        void Button13Clicked();
        void Button14Clicked();
        void Button15Clicked();
        void Button16Clicked();
        void Button17Clicked();
        void Button18Clicked();
        void Button19Clicked();
        void Button20Clicked();
        void Button21Clicked();
        void Button22Clicked();
        void Button23Clicked();
        void Button24Clicked();
        void Button25Clicked();
        void Button26Clicked();
        void Button27Clicked();
        void Button28Clicked();
        void Button29Clicked();
        void Button30Clicked();
     
        private:
        int myPage = 1;
     
        QPushButton *exitButton;
        QPushButton *nextButton;
        QPushButton *previousButton;
        QPushButton *Button1;
        QPushButton *Button2;
        QPushButton *Button3;
        QPushButton *Button4;
        QPushButton *Button5;
        QPushButton *Button6;
        QPushButton *Button7;
        QPushButton *Button8;
        QPushButton *Button9;
        QPushButton *Button10;
        QPushButton *Button11;
        QPushButton *Button12;
        QPushButton *Button13;
        QPushButton *Button14;
        QPushButton *Button15;
        QPushButton *Button16;
        QPushButton *Button17;
        QPushButton *Button18;
        QPushButton *Button19;
        QPushButton *Button20;
        QPushButton *Button21;
        QPushButton *Button22;
        QPushButton *Button23;
        QPushButton *Button24;
        QPushButton *Button25;
        QPushButton *Button26;
        QPushButton *Button27;
        QPushButton *Button28;
        QPushButton *Button29;
        QPushButton *Button30;
     
        QPushButton *logo;
        QPushButton *markPic;
        QLabel *seriesLabel;
     
        FinalWindow finalWindow;
     
        void Button();
        void SetInfo();
        void Slots();
        void RunFinal(std::string model);
    };
     
    #endif // BROTHERDCPSERIESWINDOW
    BrotherDCPSeriesWindow.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
    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
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    #include "BrotherDCPSeriesWindow.h"
     
    BrotherDCPSeriesWindow::BrotherDCPSeriesWindow() : QWidget()
    {
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Brother - Série DCP"));
     
        Button();
        Slots();
    }
     
    //############### Private functions ###############
    void BrotherDCPSeriesWindow::Button()
    {
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        markPic = new QPushButton(QIcon("pictures/brother.png"), "", this);
        markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        markPic->setGeometry(Init::MARK_SERIES_X, Init::MARK_SERIES_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->setFlat(true);
     
        seriesLabel = new QLabel("Série DCP", this);
        seriesLabel->setGeometry(Init::SERIES_LABEL_X, Init::SERIES_LABEL_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        seriesLabel->setFont(Init::FONT1);
        seriesLabel->setAlignment(Qt::AlignCenter);
     
        exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
        exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
     
        nextButton = new QPushButton(QIcon("pictures/next.png"), "", this);
        nextButton->setGeometry(Init::EXIT_X - 75, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        nextButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        nextButton->setFlat(true);
     
        previousButton = new QPushButton(QIcon("pictures/previous.png"), "", this);
        previousButton->setGeometry(Init::EXIT_X - 150, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        previousButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        previousButton->setFlat(true);
     
        Button1 = new QPushButton(this);
        Button1->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_1, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button1->setFont(Init::FONT2);
     
        Button2 = new QPushButton(this);
        Button2->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_1, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button2->setFont(Init::FONT2);
     
        Button3 = new QPushButton(this);
        Button3->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_1, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button3->setFont(Init::FONT2);
     
        Button4 = new QPushButton(this);
        Button4->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_1, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button4->setFont(Init::FONT2);
     
        Button5 = new QPushButton(this);
        Button5->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_1, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button5->setFont(Init::FONT2);
     
        Button6 = new QPushButton(this);
        Button6->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button6->setFont(Init::FONT2);
     
        Button7 = new QPushButton(this);
        Button7->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button7->setFont(Init::FONT2);
     
        Button8 = new QPushButton(this);
        Button8->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button8->setFont(Init::FONT2);
     
        Button9 = new QPushButton(this);
        Button9->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button9->setFont(Init::FONT2);
     
        Button10 = new QPushButton(this);
        Button10->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button10->setFont(Init::FONT2);
     
        Button11 = new QPushButton(this);
        Button11->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button11->setFont(Init::FONT2);
     
        Button12 = new QPushButton(this);
        Button12->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button12->setFont(Init::FONT2);
     
        Button13 = new QPushButton(this);
        Button13->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button13->setFont(Init::FONT2);
     
        Button14 = new QPushButton(this);
        Button14->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button14->setFont(Init::FONT2);
     
        Button15 = new QPushButton(this);
        Button15->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button15->setFont(Init::FONT2);
     
        Button16 = new QPushButton(this);
        Button16->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button16->setFont(Init::FONT2);
     
        Button17 = new QPushButton(this);
        Button17->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button17->setFont(Init::FONT2);
     
        Button18 = new QPushButton(this);
        Button18->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button18->setFont(Init::FONT2);
     
        Button19 = new QPushButton(this);
        Button19->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button19->setFont(Init::FONT2);
     
        Button20 = new QPushButton(this);
        Button20->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button20->setFont(Init::FONT2);
     
        Button21 = new QPushButton(this);
        Button21->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button21->setFont(Init::FONT2);
     
        Button22 = new QPushButton(this);
        Button22->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button22->setFont(Init::FONT2);
     
        Button23 = new QPushButton(this);
        Button23->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button23->setFont(Init::FONT2);
     
        Button24 = new QPushButton(this);
        Button24->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button24->setFont(Init::FONT2);
     
        Button25 = new QPushButton(this);
        Button25->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button25->setFont(Init::FONT2);
     
        Button26 = new QPushButton(this);
        Button26->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button26->setFont(Init::FONT2);
     
        Button27 = new QPushButton(this);
        Button27->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button27->setFont(Init::FONT2);
     
        Button28 = new QPushButton(this);
        Button28->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button28->setFont(Init::FONT2);
     
        Button29 = new QPushButton(this);
        Button29->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button29->setFont(Init::FONT2);
     
        Button30 = new QPushButton(this);
        Button30->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button30->setFont(Init::FONT2);
     
        SetInfo();
    }
     
    void BrotherDCPSeriesWindow::SetInfo()
    {
        if (myPage == 1)
        {
            nextButton->show();
            previousButton->hide();
            Button1->setText("105CN");
            Button2->setText("110C");
            Button3->setText("115C");
            Button4->setText("117C");
            Button5->setText("120C");
            Button6->setText("130C");
            Button7->setText("135C");
            Button8->setText("145C");
            Button9->setText("150C");
            Button10->setText("153C");
            Button11->setText("163C");
            Button12->setText("165C");
            Button13->setText("167C");
            Button14->setText("185C");
            Button15->setText("193C");
            Button16->setText("195C");
            Button17->setText("197C");
            Button18->setText("310C");
            Button19->setText("310CN");
            Button20->setText("315CN");
            Button21->setText("330C");
            Button22->setText("330CN");
            Button23->setText("340CW");
            Button24->setText("340DCW");
            Button25->setText("350C");
            Button26->setText("353C");
            Button27->setText("357C");
            Button28->setText("365CN");
            Button29->setText("373CW");
            Button30->setText("375CW");
            Button30->show();
        }
        else if (myPage == 2)
        {
            nextButton->hide();
            previousButton->show();
            Button1->setText("377CW");
            Button2->setText("383C");
            Button3->setText("385C");
            Button4->setText("387C");
            Button5->setText("395CN");
            Button6->setText("540CN");
            Button7->setText("560CN");
            Button8->setText("585CW");
            Button9->setText("750CW");
            Button10->setText("770CW");
            Button11->setText("4020C");
            Button12->setText("6690CW");
            Button13->setText("J125");
            Button14->setText("J132W");
            Button15->setText("J140W");
            Button16->setText("J152W");
            Button17->setText("J172W");
            Button18->setText("J265W");
            Button19->setText("J315W");
            Button20->setText("J515W");
            Button21->setText("J525W");
            Button22->setText("J552DW");
            Button23->setText("J625DW");
            Button24->setText("J715W");
            Button25->setText("J725DW");
            Button26->setText("J752DW");
            Button27->setText("J925DW");
            Button28->setText("J4110DW");
            Button29->setText("J4120DW");
            Button30->hide();
        }
    }
     
    void BrotherDCPSeriesWindow::Slots()
    {
        connect(exitButton, SIGNAL(clicked()), this, SLOT(close()));
        connect(nextButton, SIGNAL(clicked()), this, SLOT(NextClicked()));
        connect(previousButton, SIGNAL(clicked()), this, SLOT(PreviousClicked()));
        connect(Button1, SIGNAL(clicked()), this, SLOT(Button1Clicked()));
        connect(Button2, SIGNAL(clicked()), this, SLOT(Button2Clicked()));
        connect(Button3, SIGNAL(clicked()), this, SLOT(Button3Clicked()));
        connect(Button4, SIGNAL(clicked()), this, SLOT(Button4Clicked()));
        connect(Button5, SIGNAL(clicked()), this, SLOT(Button5Clicked()));
        connect(Button6, SIGNAL(clicked()), this, SLOT(Button6Clicked()));
        connect(Button7, SIGNAL(clicked()), this, SLOT(Button7Clicked()));
        connect(Button8, SIGNAL(clicked()), this, SLOT(Button8Clicked()));
        connect(Button9, SIGNAL(clicked()), this, SLOT(Button9Clicked()));
        connect(Button10, SIGNAL(clicked()), this, SLOT(Button10Clicked()));
        connect(Button11, SIGNAL(clicked()), this, SLOT(Button11Clicked()));
        connect(Button12, SIGNAL(clicked()), this, SLOT(Button12Clicked()));
        connect(Button13, SIGNAL(clicked()), this, SLOT(Button13Clicked()));
        connect(Button14, SIGNAL(clicked()), this, SLOT(Button14Clicked()));
        connect(Button15, SIGNAL(clicked()), this, SLOT(Button15Clicked()));
        connect(Button16, SIGNAL(clicked()), this, SLOT(Button16Clicked()));
        connect(Button17, SIGNAL(clicked()), this, SLOT(Button17Clicked()));
        connect(Button18, SIGNAL(clicked()), this, SLOT(Button18Clicked()));
        connect(Button19, SIGNAL(clicked()), this, SLOT(Button19Clicked()));
        connect(Button20, SIGNAL(clicked()), this, SLOT(Button20Clicked()));
        connect(Button21, SIGNAL(clicked()), this, SLOT(Button21Clicked()));
        connect(Button22, SIGNAL(clicked()), this, SLOT(Button22Clicked()));
        connect(Button23, SIGNAL(clicked()), this, SLOT(Button23Clicked()));
        connect(Button24, SIGNAL(clicked()), this, SLOT(Button24Clicked()));
        connect(Button25, SIGNAL(clicked()), this, SLOT(Button25Clicked()));
        connect(Button26, SIGNAL(clicked()), this, SLOT(Button26Clicked()));
        connect(Button27, SIGNAL(clicked()), this, SLOT(Button27Clicked()));
        connect(Button28, SIGNAL(clicked()), this, SLOT(Button28Clicked()));
        connect(Button29, SIGNAL(clicked()), this, SLOT(Button29Clicked()));
        connect(Button30, SIGNAL(clicked()), this, SLOT(Button30Clicked()));
    }
     
    void BrotherDCPSeriesWindow::RunFinal(std::string model)
    {
        close();
        finalWindow.show();
        finalWindow.SetInfos(model, "brother");
    }
     
    //############### Private slots ###############
    void BrotherDCPSeriesWindow::NextClicked()
    {
        myPage++;
        SetInfo();
    }
     
    void BrotherDCPSeriesWindow::PreviousClicked()
    {
        myPage--;
        SetInfo();
    }
     
    void BrotherDCPSeriesWindow::Button1Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-105CN");
        else if (myPage == 2)
            RunFinal("DCP-377CW");
    }
     
    void BrotherDCPSeriesWindow::Button2Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-110C");
        else if (myPage == 2)
            RunFinal("DCP-383C");
    }
     
    void BrotherDCPSeriesWindow::Button3Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-115C");
        else if (myPage == 2)
            RunFinal("DCP-385C");
    }
     
    void BrotherDCPSeriesWindow::Button4Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-117C");
        else if (myPage == 2)
            RunFinal("DCP-387C");
    }
     
    void BrotherDCPSeriesWindow::Button5Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-120C");
        else if (myPage == 2)
            RunFinal("DCP-395CN");
    }
     
    void BrotherDCPSeriesWindow::Button6Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-130C");
        else if (myPage == 2)
            RunFinal("DCP-540CN");
    }
     
    void BrotherDCPSeriesWindow::Button7Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-135C");
        else if (myPage == 2)
            RunFinal("DCP-560CN");
    }
     
    void BrotherDCPSeriesWindow::Button8Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-145C");
        else if (myPage == 2)
            RunFinal("DCP-585CW");
    }
     
    void BrotherDCPSeriesWindow::Button9Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-150C");
        else if (myPage == 2)
            RunFinal("DCP-750CW");
    }
     
    void BrotherDCPSeriesWindow::Button10Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-153C");
        else if (myPage == 2)
            RunFinal("DCP-770CW");
    }
     
    void BrotherDCPSeriesWindow::Button11Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-163C");
        else if (myPage == 2)
            RunFinal("DCP-4020C");
    }
     
    void BrotherDCPSeriesWindow::Button12Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-165C");
        else if (myPage == 2)
            RunFinal("DCP-6690CW");
    }
     
    void BrotherDCPSeriesWindow::Button13Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-167C");
        else if (myPage == 2)
            RunFinal("DCP-J125");
    }
     
    void BrotherDCPSeriesWindow::Button14Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-185C");
        else if (myPage == 2)
            RunFinal("DCP-J132W");
    }
     
    void BrotherDCPSeriesWindow::Button15Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-193C");
        else if (myPage == 2)
            RunFinal("DCP-J140W");
    }
     
    void BrotherDCPSeriesWindow::Button16Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-195C");
        else if (myPage == 2)
            RunFinal("DCP-J152W");
    }
     
    void BrotherDCPSeriesWindow::Button17Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-197C");
        else if (myPage == 2)
            RunFinal("DCP-J172W");
    }
     
    void BrotherDCPSeriesWindow::Button18Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-310C");
        else if (myPage == 2)
            RunFinal("DCP-J265W");
    }
     
    void BrotherDCPSeriesWindow::Button19Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-310CN");
        else if (myPage == 2)
            RunFinal("DCP-J315W");
    }
     
    void BrotherDCPSeriesWindow::Button20Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-315CN");
        else if (myPage == 2)
            RunFinal("DCP-J515W");
    }
     
    void BrotherDCPSeriesWindow::Button21Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-330C");
        else if (myPage == 2)
            RunFinal("DCP-J525W");
    }
     
    void BrotherDCPSeriesWindow::Button22Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-330CN");
        else if (myPage == 2)
            RunFinal("DCP-J552DW");
    }
     
    void BrotherDCPSeriesWindow::Button23Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-340CW");
        else if (myPage == 2)
            RunFinal("DCP-J625DW");
    }
     
    void BrotherDCPSeriesWindow::Button24Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-340DCW");
        else if (myPage == 2)
            RunFinal("DCP-J715W");
    }
     
    void BrotherDCPSeriesWindow::Button25Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-350C");
        else if (myPage == 2)
            RunFinal("DCP-J725DW");
    }
     
    void BrotherDCPSeriesWindow::Button26Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-353C");
        else if (myPage == 2)
            RunFinal("DCP-J752DW");
    }
     
    void BrotherDCPSeriesWindow::Button27Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-357C");
        else if (myPage == 2)
            RunFinal("DCP-J925DW");
    }
     
    void BrotherDCPSeriesWindow::Button28Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-365CN");
        else if (myPage == 2)
            RunFinal("DCP-J4110DW");
    }
     
    void BrotherDCPSeriesWindow::Button29Clicked()
    {
        if (myPage == 1)
            RunFinal("DCP-373CW");
        else if (myPage == 2)
            RunFinal("DCP-J4120DW");
    }
     
    void BrotherDCPSeriesWindow::Button30Clicked()
    {
        RunFinal("DCP-375CW");
    }
    Et enfin la page finale qui affiche les références des cartouches :
    FinalWindow.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
    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
    #ifndef FINALWINDOW
    #define FINALWINDOW
     
    #include <QtWidgets>
    #include <fstream>
    #include "Init.h"
     
    class FinalWindow : public QWidget
     
    {
        Q_OBJECT
     
        public:
        FinalWindow();
        void SetInfos(std::string model, std::string mark);
     
        private slots:
     
        private:
        QPushButton *exitButton;
     
        QPushButton *logo;
        QPushButton *markPic;
        QLabel *modelLabel;
     
        // 1st line labels
        QLabel *typeLabel;
        QLabel *blackLabel;
        QLabel *magentaLabel;
        QLabel *cyanLabel;
        QLabel *yellowLabel;
        QLabel *capacityLabel;
     
        // 2nd line labels
        QLabel *refNorm;
        QLabel *refBlack;
        QLabel *refMagenta;
        QLabel *refCyan;
        QLabel *refYellow;
        QLabel *normalLabel;
     
        // 3rd line labels
        QLabel *nPageNorm;
        QLabel *nPageBlack;
        QLabel *nPageMagenta;
        QLabel *nPageCyan;
        QLabel *nPageYellow;
     
        // 4th line labels
        QLabel *refXL;
        QLabel *refBlackXL;
        QLabel *refMagentaXL;
        QLabel *refCyanXL;
        QLabel *refYellowXL;
        QLabel *XLLabel;
     
        // 5th line labels
        QLabel *nPageXL;
        QLabel *nPageBlackXL;
        QLabel *nPageMagentaXL;
        QLabel *nPageCyanXL;
        QLabel *nPageYellowXL;
     
        // 6th line labels
        QLabel *refXXL;
        QLabel *refBlackXXL;
        QLabel *refMagentaXXL;
        QLabel *refCyanXXL;
        QLabel *refYellowXXL;
        QLabel *XXLLabel;
     
        // 7th line labels
        QLabel *nPageXXL;
        QLabel *nPageBlackXXL;
        QLabel *nPageMagentaXXL;
        QLabel *nPageCyanXXL;
        QLabel *nPageYellowXXL;
     
        // 8th line labels
        QLabel *infoLabel1;
     
        void Button();
        void Slots();
        std::string ReadInfos(std::ifstream &file);
        void SearchInfos(std::ifstream &file, std::string model);
        void AssignInfos(std::ifstream &file);
    };
     
    #endif // FINALWINDOW
    FinalWindow.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
    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
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    #include "FinalWindow.h"
     
    FinalWindow::FinalWindow() : QWidget()
    {
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Final"));
     
        Button();
        Slots();
    }
     
    void FinalWindow::SetInfos(std::string model, std::string mark)
    {
        modelLabel->setText(QString::fromStdString(model));
        markPic->setIcon(QIcon(QString::fromStdString("pictures/" + mark + ".png")));
     
        std::ifstream file("database.txt");
        SearchInfos(file, model);
    }
     
    //############### Private functions ###############
    void FinalWindow::Button()
    {
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        markPic = new QPushButton;
        markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        markPic->setGeometry(Init::MARK_SERIES_X, Init::MARK_SERIES_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->setParent(this);
        markPic->setFlat(true);
     
        modelLabel = new QLabel(this);
        modelLabel->setGeometry(Init::SERIES_LABEL_X, Init::SERIES_LABEL_Y, Init::FINAL_LABEL_WIDTH, Init::FINAL_LABEL_HEIGHT);
        modelLabel->setFont(Init::FONT3);
        modelLabel->setAlignment(Qt::AlignCenter);
     
        // 1st line labels
        typeLabel = new QLabel(this);
        typeLabel->setGeometry(Init::FINAL_COL_1, Init::FINAL_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        typeLabel->setFont(Init::FONT4);
        typeLabel->setAlignment(Qt::AlignCenter);
     
        blackLabel = new QLabel(tr("Noir"), this);
        blackLabel->setGeometry(Init::FINAL_COL_2, Init::FINAL_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        blackLabel->setFont(Init::FONT2);
        blackLabel->setAlignment(Qt::AlignCenter);
        blackLabel->setStyleSheet("QLabel { background-color : black; color : white}");
     
        magentaLabel = new QLabel(tr("Magenta"), this);
        magentaLabel->setGeometry(Init::FINAL_COL_3, Init::FINAL_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        magentaLabel->setFont(Init::FONT2);
        magentaLabel->setAlignment(Qt::AlignCenter);
        magentaLabel->setStyleSheet("QLabel { background-color : magenta}");
     
        cyanLabel = new QLabel(tr("Cyan"), this);
        cyanLabel->setGeometry(Init::FINAL_COL_4, Init::FINAL_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        cyanLabel->setFont(Init::FONT2);
        cyanLabel->setAlignment(Qt::AlignCenter);
        cyanLabel->setStyleSheet("QLabel { background-color : cyan}");
     
        yellowLabel = new QLabel(tr("Jaune"), this);
        yellowLabel->setGeometry(Init::FINAL_COL_5, Init::FINAL_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        yellowLabel->setFont(Init::FONT2);
        yellowLabel->setAlignment(Qt::AlignCenter);
        yellowLabel->setStyleSheet("QLabel { background-color : yellow}");
     
        capacityLabel = new QLabel(tr("Type"), this);
        capacityLabel->setGeometry(Init::FINAL_COL_6, Init::FINAL_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        capacityLabel->setFont(Init::FONT2);
        capacityLabel->setAlignment(Qt::AlignCenter);
     
        // 2nd line labels
        refNorm = new QLabel(tr("Référence :"), this);
        refNorm->setGeometry(Init::FINAL_COL_1, Init::FINAL_LIN_2, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refNorm->setFont(Init::FONT2);
        refNorm->setAlignment(Qt::AlignCenter);
     
        refBlack = new QLabel(this);
        refBlack->setGeometry(Init::FINAL_COL_2, Init::FINAL_LIN_2, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refBlack->setFont(Init::FONT2);
        refBlack->setAlignment(Qt::AlignCenter);
        refBlack->setStyleSheet("QLabel { background-color : black; color : white}");
     
        refMagenta = new QLabel(this);
        refMagenta->setGeometry(Init::FINAL_COL_3, Init::FINAL_LIN_2, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refMagenta->setFont(Init::FONT2);
        refMagenta->setAlignment(Qt::AlignCenter);
        refMagenta->setStyleSheet("QLabel { background-color : magenta}");
     
        refCyan = new QLabel(this);
        refCyan->setGeometry(Init::FINAL_COL_4, Init::FINAL_LIN_2, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refCyan->setFont(Init::FONT2);
        refCyan->setAlignment(Qt::AlignCenter);
        refCyan->setStyleSheet("QLabel { background-color : cyan}");
     
        refYellow = new QLabel(this);
        refYellow->setGeometry(Init::FINAL_COL_5, Init::FINAL_LIN_2, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refYellow->setFont(Init::FONT2);
        refYellow->setAlignment(Qt::AlignCenter);
        refYellow->setStyleSheet("QLabel { background-color : yellow}");
     
        normalLabel = new QLabel(tr("NORMAL"), this);
        normalLabel->setGeometry(Init::FINAL_COL_6, Init::FINAL_LIN_2, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        normalLabel->setFont(Init::FONT2);
        normalLabel->setAlignment(Qt::AlignCenter);
     
        // 3rd line labels
        nPageNorm = new QLabel(tr("Nombre pages*"), this);
        nPageNorm->setGeometry(Init::FINAL_COL_1, Init::FINAL_LIN_3, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageNorm->setFont(Init::FONT2);
        nPageNorm->setAlignment(Qt::AlignCenter);
     
        nPageBlack = new QLabel(this);
        nPageBlack->setGeometry(Init::FINAL_COL_2, Init::FINAL_LIN_3, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageBlack->setFont(Init::FONT2);
        nPageBlack->setAlignment(Qt::AlignCenter);
     
        nPageMagenta = new QLabel(this);
        nPageMagenta->setGeometry(Init::FINAL_COL_3, Init::FINAL_LIN_3, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageMagenta->setFont(Init::FONT2);
        nPageMagenta->setAlignment(Qt::AlignCenter);
     
        nPageCyan = new QLabel(this);
        nPageCyan->setGeometry(Init::FINAL_COL_4, Init::FINAL_LIN_3, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageCyan->setFont(Init::FONT2);
        nPageCyan->setAlignment(Qt::AlignCenter);
     
        nPageYellow = new QLabel(this);
        nPageYellow->setGeometry(Init::FINAL_COL_5, Init::FINAL_LIN_3, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageYellow->setFont(Init::FONT2);
        nPageYellow->setAlignment(Qt::AlignCenter);
     
        // 4th line labels
        refXL = new QLabel(tr("Référence :"), this);
        refXL->setGeometry(Init::FINAL_COL_1, Init::FINAL_LIN_4, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refXL->setFont(Init::FONT2);
        refXL->setAlignment(Qt::AlignCenter);
     
        refBlackXL = new QLabel(this);
        refBlackXL->setGeometry(Init::FINAL_COL_2, Init::FINAL_LIN_4, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refBlackXL->setFont(Init::FONT2);
        refBlackXL->setAlignment(Qt::AlignCenter);
        refBlackXL->setStyleSheet("QLabel { background-color : black; color : white}");
     
        refMagentaXL = new QLabel(this);
        refMagentaXL->setGeometry(Init::FINAL_COL_3, Init::FINAL_LIN_4, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refMagentaXL->setFont(Init::FONT2);
        refMagentaXL->setAlignment(Qt::AlignCenter);
        refMagentaXL->setStyleSheet("QLabel { background-color : magenta}");
     
        refCyanXL = new QLabel(this);
        refCyanXL->setGeometry(Init::FINAL_COL_4, Init::FINAL_LIN_4, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refCyanXL->setFont(Init::FONT2);
        refCyanXL->setAlignment(Qt::AlignCenter);
        refCyanXL->setStyleSheet("QLabel { background-color : cyan}");
     
        refYellowXL = new QLabel(this);
        refYellowXL->setGeometry(Init::FINAL_COL_5, Init::FINAL_LIN_4, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refYellowXL->setFont(Init::FONT2);
        refYellowXL->setAlignment(Qt::AlignCenter);
        refYellowXL->setStyleSheet("QLabel { background-color : yellow}");
     
        XLLabel = new QLabel(tr("XL"), this);
        XLLabel->setGeometry(Init::FINAL_COL_6, Init::FINAL_LIN_4, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        XLLabel->setFont(Init::FONT2);
        XLLabel->setAlignment(Qt::AlignCenter);
     
        // 5th line labels
        nPageXL = new QLabel(tr("Nombre pages*"), this);
        nPageXL->setGeometry(Init::FINAL_COL_1, Init::FINAL_LIN_5, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageXL->setFont(Init::FONT2);
        nPageXL->setAlignment(Qt::AlignCenter);
     
        nPageBlackXL = new QLabel(this);
        nPageBlackXL->setGeometry(Init::FINAL_COL_2, Init::FINAL_LIN_5, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageBlackXL->setFont(Init::FONT2);
        nPageBlackXL->setAlignment(Qt::AlignCenter);
     
        nPageMagentaXL = new QLabel(this);
        nPageMagentaXL->setGeometry(Init::FINAL_COL_3, Init::FINAL_LIN_5, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageMagentaXL->setFont(Init::FONT2);
        nPageMagentaXL->setAlignment(Qt::AlignCenter);
     
        nPageCyanXL = new QLabel(this);
        nPageCyanXL->setGeometry(Init::FINAL_COL_4, Init::FINAL_LIN_5, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageCyanXL->setFont(Init::FONT2);
        nPageCyanXL->setAlignment(Qt::AlignCenter);
     
        nPageYellowXL = new QLabel(this);
        nPageYellowXL->setGeometry(Init::FINAL_COL_5, Init::FINAL_LIN_5, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageYellowXL->setFont(Init::FONT2);
        nPageYellowXL->setAlignment(Qt::AlignCenter);
     
        // 6th line labels
        refXXL = new QLabel(tr("Référence :"), this);
        refXXL->setGeometry(Init::FINAL_COL_1, Init::FINAL_LIN_6, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refXXL->setFont(Init::FONT2);
        refXXL->setAlignment(Qt::AlignCenter);
     
        refBlackXXL = new QLabel(this);
        refBlackXXL->setGeometry(Init::FINAL_COL_2, Init::FINAL_LIN_6, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refBlackXXL->setFont(Init::FONT2);
        refBlackXXL->setAlignment(Qt::AlignCenter);
        refBlackXXL->setStyleSheet("QLabel { background-color : black; color : white}");
     
        refMagentaXXL = new QLabel(this);
        refMagentaXXL->setGeometry(Init::FINAL_COL_3, Init::FINAL_LIN_6, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refMagentaXXL->setFont(Init::FONT2);
        refMagentaXXL->setAlignment(Qt::AlignCenter);
        refMagentaXXL->setStyleSheet("QLabel { background-color : magenta}");
     
        refCyanXXL = new QLabel(this);
        refCyanXXL->setGeometry(Init::FINAL_COL_4, Init::FINAL_LIN_6, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refCyanXXL->setFont(Init::FONT2);
        refCyanXXL->setAlignment(Qt::AlignCenter);
        refCyanXXL->setStyleSheet("QLabel { background-color : cyan}");
     
        refYellowXXL = new QLabel(this);
        refYellowXXL->setGeometry(Init::FINAL_COL_5, Init::FINAL_LIN_6, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        refYellowXXL->setFont(Init::FONT2);
        refYellowXXL->setAlignment(Qt::AlignCenter);
        refYellowXXL->setStyleSheet("QLabel { background-color : yellow}");
     
        XXLLabel = new QLabel(this);
        XXLLabel->setGeometry(Init::FINAL_COL_6, Init::FINAL_LIN_6, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        XXLLabel->setFont(Init::FONT2);
        XXLLabel->setAlignment(Qt::AlignCenter);
     
        // 7th line labels
        nPageXXL = new QLabel(tr("Nombre pages*"), this);
        nPageXXL->setGeometry(Init::FINAL_COL_1, Init::FINAL_LIN_7, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageXXL->setFont(Init::FONT2);
        nPageXXL->setAlignment(Qt::AlignCenter);
     
        nPageBlackXXL = new QLabel(this);
        nPageBlackXXL->setGeometry(Init::FINAL_COL_2, Init::FINAL_LIN_7, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageBlackXXL->setFont(Init::FONT2);
        nPageBlackXXL->setAlignment(Qt::AlignCenter);
     
        nPageMagentaXXL = new QLabel(this);
        nPageMagentaXXL->setGeometry(Init::FINAL_COL_3, Init::FINAL_LIN_7, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageMagentaXXL->setFont(Init::FONT2);
        nPageMagentaXXL->setAlignment(Qt::AlignCenter);
     
        nPageCyanXXL = new QLabel(this);
        nPageCyanXXL->setGeometry(Init::FINAL_COL_4, Init::FINAL_LIN_7, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageCyanXXL->setFont(Init::FONT2);
        nPageCyanXXL->setAlignment(Qt::AlignCenter);
     
        nPageYellowXXL = new QLabel(this);
        nPageYellowXXL->setGeometry(Init::FINAL_COL_5, Init::FINAL_LIN_7, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        nPageYellowXXL->setFont(Init::FONT2);
        nPageYellowXXL->setAlignment(Qt::AlignCenter);
     
        // 8th line labels
        infoLabel1 = new QLabel(tr("<i>* Données constructeur (nombre de pages A4)<br>Pour les cartouches photos le nombre de pages estimées est le nombre de photos 10x15</i>"), this);
        infoLabel1->setGeometry(Init::FINAL_COL_2, Init::FINAL_LIN_8, Init::FINAL_WIDTH * 5, Init::FINAL_HEIGHT * 2);
        infoLabel1->setFont(Init::FONT2);
     
        exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
        exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
    }
     
    void FinalWindow::Slots()
    {
        connect(exitButton, SIGNAL(clicked()), this, SLOT(close()));
    }
     
    std::string FinalWindow::ReadInfos(std::ifstream &file)
    {
        std::string word;
        file >> word;
        return word;
    }
     
    void FinalWindow::SearchInfos(std::ifstream &file, std::string model)
    {
        std::string line;
        while(getline(file, line))
        {
            if(line == model)
            {
                AssignInfos(file);
            }
        }
    }
     
    void FinalWindow::AssignInfos(std::ifstream &file)
    {
        typeLabel->setText(QString::fromStdString(ReadInfos(file)));
     
        refBlack->setText(QString::fromStdString(ReadInfos(file)));
        refMagenta->setText(QString::fromStdString(ReadInfos(file)));
        refCyan->setText(QString::fromStdString(ReadInfos(file)));
        refYellow->setText(QString::fromStdString(ReadInfos(file)));
     
        refBlackXL->setText(QString::fromStdString(ReadInfos(file)));
        refMagentaXL->setText(QString::fromStdString(ReadInfos(file)));
        refCyanXL->setText(QString::fromStdString(ReadInfos(file)));
        refYellowXL->setText(QString::fromStdString(ReadInfos(file)));
     
        refBlackXXL->setText(QString::fromStdString(ReadInfos(file)));
        refMagentaXXL->setText(QString::fromStdString(ReadInfos(file)));
        refCyanXXL->setText(QString::fromStdString(ReadInfos(file)));
        refYellowXXL->setText(QString::fromStdString(ReadInfos(file)));
     
        nPageBlack->setText(QString::fromStdString(ReadInfos(file)));
        nPageMagenta->setText(QString::fromStdString(ReadInfos(file)));
        nPageCyan->setText(QString::fromStdString(ReadInfos(file)));
        nPageYellow->setText(QString::fromStdString(ReadInfos(file)));
     
        nPageBlackXL->setText(QString::fromStdString(ReadInfos(file)));
        nPageMagentaXL->setText(QString::fromStdString(ReadInfos(file)));
        nPageCyanXL->setText(QString::fromStdString(ReadInfos(file)));
        nPageYellowXL->setText(QString::fromStdString(ReadInfos(file)));
     
        nPageBlackXXL->setText(QString::fromStdString(ReadInfos(file)));
        nPageMagentaXXL->setText(QString::fromStdString(ReadInfos(file)));
        nPageCyanXXL->setText(QString::fromStdString(ReadInfos(file)));
        nPageYellowXXL->setText(QString::fromStdString(ReadInfos(file)));
     
        if (typeLabel->text().toStdString() == "Cartouche")
            XXLLabel->setText("PHOTO");
        else
            XXLLabel->setText("XXL");
    }

  3. #3
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 577
    Points
    218 577
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Quand j'exécute mon application elle utilise environ 440 Mo de mémoire vive à peine ouverte et à chaque fois que je clique sur un bouton (pour ouvrir la page suivante) cela me rajoute 5 Mo à chaque fois seulement au 1er lancement de chaque page (exemple, si j'ouvre 10 fois la page de la marque 1, je n'ai qu'une fois 5 Mo ajouté).
    Même si le constat est flagrant, ce n'est pas la bonne méthode (du moins, pas celle qui est scientifique et utile). La bonne méthode c'est d'utiliser un outil comme valgrind/Dr Memory pour avoir un vrai rapport sur l'utilisation mémoire. On lira donc ce tutoriel : http://alexandre-laurent.developpez....pplication/#L6

    En C++ (C++11 précisément), on a pas besoin de gérer la mémoire soi même. Plus précisément, on a pas besoin de faire de new/delete. Les pointeurs devraient tous être encapsulé dans des pointeurs intelligents (shared_ptd/unique_ptr).
    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
    void Button1Clicked();
        void Button2Clicked();
        void Button3Clicked();
        void Button4Clicked();
        void Button5Clicked();
        void Button6Clicked();
        void Button7Clicked();
        void Button8Clicked();
        void Button9Clicked();
        void Button10Clicked();
        void Button11Clicked();
        void Button12Clicked();
        void Button13Clicked();
        void Button14Clicked();
        void Button15Clicked();
        void Button16Clicked();
        void Button17Clicked();
        void Button18Clicked();
        void Button19Clicked();
        void Button20Clicked();
        void Button21Clicked();
        void Button22Clicked();
        void Button23Clicked();
        void Button24Clicked();
        void Button25Clicked();
        void Button26Clicked();
        void Button27Clicked();
        void Button28Clicked();
        void Button29Clicked();
        void Button30Clicked();
    Ne voulez vous pas faire un QSignalMapper :'(
    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
    Button4 = new QPushButton(this);
        Button4->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_1, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button4->setFont(Init::FONT2);
     
        Button5 = new QPushButton(this);
        Button5->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_1, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button5->setFont(Init::FONT2);
     
        Button6 = new QPushButton(this);
        Button6->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button6->setFont(Init::FONT2);
     
        Button7 = new QPushButton(this);
        Button7->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button7->setFont(Init::FONT2);
     
        Button8 = new QPushButton(this);
        Button8->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button8->setFont(Init::FONT2);
     
        Button9 = new QPushButton(this);
        Button9->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button9->setFont(Init::FONT2);
     
        Button10 = new QPushButton(this);
        Button10->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_2, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button10->setFont(Init::FONT2);
     
        Button11 = new QPushButton(this);
        Button11->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button11->setFont(Init::FONT2);
     
        Button12 = new QPushButton(this);
        Button12->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button12->setFont(Init::FONT2);
     
        Button13 = new QPushButton(this);
        Button13->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button13->setFont(Init::FONT2);
     
        Button14 = new QPushButton(this);
        Button14->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button14->setFont(Init::FONT2);
     
        Button15 = new QPushButton(this);
        Button15->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_3, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button15->setFont(Init::FONT2);
     
        Button16 = new QPushButton(this);
        Button16->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button16->setFont(Init::FONT2);
     
        Button17 = new QPushButton(this);
        Button17->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button17->setFont(Init::FONT2);
     
        Button18 = new QPushButton(this);
        Button18->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button18->setFont(Init::FONT2);
     
        Button19 = new QPushButton(this);
        Button19->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button19->setFont(Init::FONT2);
     
        Button20 = new QPushButton(this);
        Button20->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_4, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button20->setFont(Init::FONT2);
     
        Button21 = new QPushButton(this);
        Button21->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button21->setFont(Init::FONT2);
     
        Button22 = new QPushButton(this);
        Button22->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button22->setFont(Init::FONT2);
     
        Button23 = new QPushButton(this);
        Button23->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button23->setFont(Init::FONT2);
     
        Button24 = new QPushButton(this);
        Button24->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button24->setFont(Init::FONT2);
     
        Button25 = new QPushButton(this);
        Button25->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_5, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button25->setFont(Init::FONT2);
     
        Button26 = new QPushButton(this);
        Button26->setGeometry(Init::MODEL_COL_1, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button26->setFont(Init::FONT2);
     
        Button27 = new QPushButton(this);
        Button27->setGeometry(Init::MODEL_COL_2, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button27->setFont(Init::FONT2);
     
        Button28 = new QPushButton(this);
        Button28->setGeometry(Init::MODEL_COL_3, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button28->setFont(Init::FONT2);
     
        Button29 = new QPushButton(this);
        Button29->setGeometry(Init::MODEL_COL_4, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button29->setFont(Init::FONT2);
     
        Button30 = new QPushButton(this);
        Button30->setGeometry(Init::MODEL_COL_5, Init::MODEL_LIN_6, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        Button30->setFont(Init::FONT2);
    Et un tableau, et une boucle for :'(

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    void FinalWindow::Button()
    {
    Des allocations dans cette fonction. Cela veut dire que vous demandez toujours plus de mémoire au système à chaque exécution de cette fonction. Vous ne pouvez pas réutiliser vos variables ?

    En C++11, le nouveau mot d'ordre c'est : on évite les pointeurs et les new.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Tout d'abord, merci LittleWhite.

    Depuis mon post j'ai repris mon application depuis le début.

    Plutôt que de gérer environ 175 pages, maintenant je n'en ai plus qu'une seule.

    Sur cette page j'ai :

    - des boutons pour les choix des marques
    - des boutons pour le choix du type (encre / laser)
    - des boutons pour le choix des familles
    (depuis hier soir j'en suis là ;-) )

    et je vais ajouter :
    - des boutons pour le choix des modèles
    - des champs de texte (QLabel) pour afficher les références

    Bien entendu je joue sur les status hide() et show() pour n'afficher que ce dont j'ai besoin au moment voulu (en fonction du bouton cliqué), et chacun de ces boutons à sa propre fonction/SLOT.

    A cet instant je n'utilise plus qu'environ 50 Mo de ram qui peuvent s'alourdir de 5 à 10 Mo mais retombent après à environ 50 Mo.

    Je vais donc suivre tes conseils et supprimer les pointeurs et les "new" et je vais également mettre en place quelques boucle pour la création des boutons...

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    A cet instant (enfin à hier soir), voici mon nouveau début de code (j'ai conservé mon fichier Init et sons header tel qu'à la première version, ne servant qu'à définir les polices et les positions)

    main.cpp (le même)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #include <QApplication>
     
    #include "MainWindow.h"
     
     
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
     
        MainWindow window;
        window.show();
     
        return app.exec();
    }
    MainWindow.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
    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
    #ifndef MAINWINDOW
    #define MAINWINDOW
     
    #include <QtWidgets>
    #include "Init.h"
     
    class MainWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        MainWindow();
     
        private slots:
        void HomeWindow();
        void runBrother();
        void runCanon();
        void runEpson();
        void runHp();
        void runLexmark();
        void runSamsung();
        void InkClicked();
        void LaserClicked();
        void NextSeriesButtonClicked();
        void PreviousSeriesButtonClicked();
     
        private:
        int myPage;
        int seriesNumber;
        std::string myMark;
     
        std::string series1;
        std::string series2;
        std::string series3;
        std::string series4;
        std::string series5;
        std::string series6;
        std::string series7;
        std::string series8;
        std::string series9;
        std::string series10;
        std::string series11;
        std::string series12;
        std::string series13;
        std::string series14;
        std::string series15;
        std::string series16;
        std::string series17;
        std::string series18;
        std::string series19;
        std::string series20;
        std::string series21;
        std::string series22;
     
     
        QPushButton *brotherButton;
        QPushButton *canonButton;
        QPushButton *epsonButton;
        QPushButton *hpButton;
        QPushButton *lexmarkButton;
        QPushButton *samsungButton;
     
        QPushButton *inkButton;
        QPushButton *laserButton;
     
        QPushButton *series1Button;
        QPushButton *series2Button;
        QPushButton *series3Button;
        QPushButton *series4Button;
        QPushButton *series5Button;
        QPushButton *series6Button;
        QPushButton *series7Button;
        QPushButton *series8Button;
        QPushButton *series9Button;
        QPushButton *series10Button;
     
        QPushButton *markPic;
        QPushButton *logo;
        QPushButton *nextSeriesButton;
        QPushButton *previousSeriesButton;
        QPushButton *exitButton;
     
        void TypeWindow();
        void HideTypeButtons();
        void HideSeriesButtons();
        void ShowSeriesFirstPage();
        void SetSeriesInfos();
        void ShowSeriesButton();
     
        void BrotherInkWindow();
        void BrotherLaserWindow();
        void CanonInkWindow();
        void CanonLaserWindow();
        void EpsonInkWindow();
        void EpsonLaserWindow();
        void HPInkWindow();
        void HPLaserWindow();
        void LexmarkInkWindow();
        void LexmarkLaserWindow();
        void SamsungInkWindow();
        void SamsungLaserWindow();
     
        void Button();
        void Slots();
    };
     
    #endif // MAINWINDOW
    MainWindow.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
    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
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    #include "MainWindow.h"
     
    MainWindow::MainWindow() : QWidget()
    {
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Ink Finder"));
     
        Button();
     
        Slots();
    }
     
    //############### Private functions ###############
    void MainWindow::Button()
    {
        //###########################################################
        //############## Mark chooser window's buttons ##############
        //###########################################################
     
        brotherButton = new QPushButton(QIcon("pictures/brother.png"), "", this);
        brotherButton->setGeometry(Init::MARK_COL_1, Init::MARK_LIN_1, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        brotherButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        brotherButton->setFlat(true);
     
        canonButton = new QPushButton(QIcon("pictures/canon.png"), "", this);
        canonButton->setGeometry(Init::MARK_COL_2, Init::MARK_LIN_1, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        canonButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        canonButton->setFlat(true);
     
        epsonButton = new QPushButton(QIcon("pictures/epson.png"), "", this);
        epsonButton->setGeometry(Init::MARK_COL_1, Init::MARK_LIN_2, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        epsonButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        epsonButton->setFlat(true);
     
        hpButton = new QPushButton(QIcon("pictures/hp.png"), "", this);
        hpButton->setGeometry(Init::MARK_COL_2, Init::MARK_LIN_2, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        hpButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        hpButton->setFlat(true);
     
        lexmarkButton = new QPushButton(QIcon("pictures/lexmark.png"), "", this);
        lexmarkButton->setGeometry(Init::MARK_COL_1, Init::MARK_LIN_3, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        lexmarkButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        lexmarkButton->setFlat(true);
     
        samsungButton = new QPushButton(QIcon("pictures/samsung.png"), "", this);
        samsungButton->setGeometry(Init::MARK_COL_2, Init::MARK_LIN_3, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        samsungButton->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        samsungButton->setFlat(true);
     
        //###########################################################
        //############## Type chooser window's buttons ##############
        //###########################################################
     
        inkButton = new QPushButton("Jet d'encre", this);
        inkButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_1, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        inkButton->setFont(Init::FONT1);
        inkButton->hide();
     
        laserButton = new QPushButton("Laser", this);
        laserButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_2, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        laserButton->setFont(Init::FONT1);
        laserButton->hide();
     
        //###########################################################
        //############# Series chooser window's buttons #############
        //###########################################################
     
        series1Button = new QPushButton(this);
        series1Button->setGeometry(Init::HOME_COL_1, Init::HOME_LIN_1, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series1Button->setFont(Init::FONT6);
        series1Button->hide();
     
        series2Button = new QPushButton(this);
        series2Button->setGeometry(Init::HOME_COL_2, Init::HOME_LIN_1, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series2Button->setFont(Init::FONT6);
        series2Button->hide();
     
        series3Button = new QPushButton(this);
        series3Button->setGeometry(Init::HOME_COL_1, Init::HOME_LIN_2, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series3Button->setFont(Init::FONT6);
        series3Button->hide();
     
        series4Button = new QPushButton(this);
        series4Button->setGeometry(Init::HOME_COL_2, Init::HOME_LIN_2, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series4Button->setFont(Init::FONT6);
        series4Button->hide();
     
        series5Button = new QPushButton(this);
        series5Button->setGeometry(Init::HOME_COL_1, Init::HOME_LIN_3, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series5Button->setFont(Init::FONT6);
        series5Button->hide();
     
        series6Button = new QPushButton(this);
        series6Button->setGeometry(Init::HOME_COL_2, Init::HOME_LIN_3, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series6Button->setFont(Init::FONT6);
        series6Button->hide();
     
        series7Button = new QPushButton(this);
        series7Button->setGeometry(Init::HOME_COL_1, Init::HOME_LIN_4, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series7Button->setFont(Init::FONT6);
        series7Button->hide();
     
        series8Button = new QPushButton(this);
        series8Button->setGeometry(Init::HOME_COL_2, Init::HOME_LIN_4, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series8Button->setFont(Init::FONT6);
        series8Button->hide();
     
        series9Button = new QPushButton(this);
        series9Button->setGeometry(Init::HOME_COL_1, Init::HOME_LIN_5, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series9Button->setFont(Init::FONT6);
        series9Button->hide();
     
        series10Button = new QPushButton(this);
        series10Button->setGeometry(Init::HOME_COL_2, Init::HOME_LIN_5, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        series10Button->setFont(Init::FONT6);
        series10Button->hide();
     
        //###########################################################
        //################# Common window's buttons #################
        //###########################################################
     
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        markPic = new QPushButton(this);
        markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->setFlat(true);
        markPic->hide();
     
        nextSeriesButton = new QPushButton(QIcon("pictures/next.png"), "", this);
        nextSeriesButton->setGeometry(Init::EXIT_X - 75, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        nextSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        nextSeriesButton->setFlat(true);
        nextSeriesButton->hide();
     
        previousSeriesButton = new QPushButton(QIcon("pictures/previous.png"), "", this);
        previousSeriesButton->setGeometry(Init::EXIT_X - 150, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        previousSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        previousSeriesButton->setFlat(true);
        previousSeriesButton->hide();
     
        exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
        exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        exitButton->hide();
    }
     
    void MainWindow::Slots()
    {
        connect(brotherButton, SIGNAL(clicked(bool)), this, SLOT(runBrother()));
        connect(canonButton, SIGNAL(clicked(bool)), this, SLOT(runCanon()));
        connect(epsonButton, SIGNAL(clicked(bool)), this, SLOT(runEpson()));
        connect(hpButton, SIGNAL(clicked(bool)), this, SLOT(runHp()));
        connect(lexmarkButton, SIGNAL(clicked(bool)), this, SLOT(runLexmark()));
        connect(samsungButton, SIGNAL(clicked(bool)), this, SLOT(runSamsung()));
        connect(exitButton, SIGNAL(clicked(bool)), this, SLOT(HomeWindow()));
        connect(nextSeriesButton, SIGNAL(clicked(bool)), this, SLOT(NextSeriesButtonClicked()));
        connect(previousSeriesButton, SIGNAL(clicked(bool)), this, SLOT(PreviousSeriesButtonClicked()));
        connect(inkButton, SIGNAL(clicked(bool)), this, SLOT(InkClicked()));
        connect(laserButton, SIGNAL(clicked(bool)), this, SLOT(LaserClicked()));
    }
     
    void MainWindow::TypeWindow()
    {
        markPic->setIcon(QIcon(QString::fromStdString("pictures/" + myMark + ".png")));
        markPic->show();
     
        brotherButton->hide();
        canonButton->hide();
        epsonButton->hide();
        hpButton->hide();
        lexmarkButton->hide();
        samsungButton->hide();
     
        inkButton->show();
        laserButton->show();
     
        exitButton->show();
    }
     
    void MainWindow::HideTypeButtons()
    {
        inkButton->hide();
        laserButton->hide();
    }
     
    void MainWindow::HideSeriesButtons()
    {
        series1Button->hide();
        series2Button->hide();
        series3Button->hide();
        series4Button->hide();
        series5Button->hide();
        series6Button->hide();
        series7Button->hide();
        series8Button->hide();
        series9Button->hide();
        series10Button->hide();
    }
     
    void MainWindow::ShowSeriesFirstPage()
    {
        series1Button->show();
        series2Button->show();
        series3Button->show();
        series4Button->show();
        series5Button->show();
        series6Button->show();
        series7Button->show();
        series8Button->show();
        series9Button->show();
        series10Button->show();
    }
     
    void MainWindow::ShowSeriesButton()
    {
        HideSeriesButtons();
     
        int n = seriesNumber - (10 * (myPage - 1));
        int pageNumber = seriesNumber / 10;
        if ((seriesNumber % 10) != 0)
            pageNumber++;
     
        if (n >= 1)
            series1Button->show();
        if (n >= 2)
            series2Button->show();
        if (n >= 3)
            series3Button->show();
        if (n >= 4)
            series4Button->show();
        if (n >= 5)
            series5Button->show();
        if (n >= 6)
            series6Button->show();
        if (n >= 7)
            series7Button->show();
        if (n >= 8)
            series8Button->show();
        if (n >= 9)
            series9Button->show();
        if (n >= 10)
            series10Button->show();
     
        if (myPage == 1)
        {
            if (pageNumber > 1)
                nextSeriesButton->show();
            else
                nextSeriesButton->hide();
     
            previousSeriesButton->hide();
        }
        if (myPage == pageNumber && pageNumber > 1)
        {
            nextSeriesButton->hide();
            previousSeriesButton->show();
        }
        if (myPage > 1 && myPage < pageNumber)
        {
            nextSeriesButton->show();
            previousSeriesButton->show();
        }
    }
     
    void MainWindow::SetSeriesInfos()
    {
        if (myPage == 1)
        {
            series1Button->setText(QString::fromStdString(series1));
            series2Button->setText(QString::fromStdString(series2));
            series3Button->setText(QString::fromStdString(series3));
            series4Button->setText(QString::fromStdString(series4));
            series5Button->setText(QString::fromStdString(series5));
            series6Button->setText(QString::fromStdString(series6));
            series7Button->setText(QString::fromStdString(series7));
            series8Button->setText(QString::fromStdString(series8));
            series9Button->setText(QString::fromStdString(series9));
            series10Button->setText(QString::fromStdString(series10));
        }
        else if (myPage == 2)
        {
            series1Button->setText(QString::fromStdString(series11));
            series2Button->setText(QString::fromStdString(series12));
            series3Button->setText(QString::fromStdString(series13));
            series4Button->setText(QString::fromStdString(series14));
            series5Button->setText(QString::fromStdString(series15));
            series6Button->setText(QString::fromStdString(series16));
            series7Button->setText(QString::fromStdString(series17));
            series8Button->setText(QString::fromStdString(series18));
            series9Button->setText(QString::fromStdString(series19));
            series10Button->setText(QString::fromStdString(series20));
        }
        ShowSeriesButton();
    }
     
    void MainWindow::BrotherInkWindow()
    {    
        HideTypeButtons();
     
        seriesNumber = 3;
     
        series1 = "DCP";
        series2 = "FAX";
        series3 = "MFC";
     
        SetSeriesInfos();
    }
     
    void MainWindow::BrotherLaserWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 6;
     
        series1 = "DCP";
        series2 = "FAX";
        series3 = "HL";
        series4 = "IntelliFax";
        series5 = "MFC";
        series6 = "WL";
     
        SetSeriesInfos();
    }
     
    void MainWindow::CanonInkWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 17;
     
        series1 = "BJ";
        series2 = "BJC";
        series3 = "BN";
        series4 = "CP";
        series5 = "DS";
        series6 = "I";
        series7 = "JX";
        series8 = "MAXIFY";
        series9 = "MG";
        series10 = "MP";
        series11 = "MultiPass";
        series12 = "MX";
        series13 = "PIXMA";
        series14 = "S";
        series15 = "SELPHY";
        series16 = "SMARTBASE";
        series17 = "StarWriter";
     
        SetSeriesInfos();
    }
     
    void MainWindow::CanonLaserWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 20;
     
        series1 = "CP";
        series2 = "FAX";
        series3 = "FC";
        series4 = "GP";
        series5 = "i-SENSYS";
        series6 = "ImageClass";
        series7 = "IR";
        series8 = "IR ADVANCE";
        series9 = "IRC";
        series10 = "Laser L";
        series11 = "LaserClass";
        series12 = "LBP";
        series13 = "MARK";
        series14 = "MF";
        series15 = "MP";
        series16 = "MultiPass";
        series17 = "NP";
        series18 = "PC";
        series19 = "PCD";
        series20 = "PowerFax";
     
        SetSeriesInfos();
    }
     
    void MainWindow::EpsonInkWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 4;
     
        series1 = "Expression";
        series2 = "PictureMate";
        series3 = "Stylus";
        series4 = "WorkForce";
     
        SetSeriesInfos();
    }
     
    void MainWindow::EpsonLaserWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 7;
     
        series1 = "ActionLaser";
        series2 = "AcuLaser";
        series3 = "EPL";
        series4 = "GQ";
        series5 = "LP";
        series6 = "M et MX";
        series7 = "WorkForce";
     
        SetSeriesInfos();
    }
     
    void MainWindow::HPInkWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 22;
     
        series1 = "Apollo";
        series2 = "Business InkJet";
        series3 = "Color Copier";
        series4 = "Color InkJet";
        series5 = "Color Printer";
        series6 = "CopyJet";
        series7 = "CP";
        series8 = "DesignJet";
        series9 = "DeskJet";
        series10 = "DeskWriter";
        series11 = "Digital Copier";
        series12 = "Envy";
        series13 = "Fax";
        series14 = "OfficeJet";
        series15 = "OfficeJet Enterprise";
        series16 = "OfficeJet Pro";
        series17 = "Photosmart";
        series18 = "Photosmart Pro";
        series19 = "Professionnal";
        series20 = "PSC";
        series21 = "QuietJet";
        series22 = "ThinkJet";
     
        SetSeriesInfos();
    }
     
    void MainWindow::HPLaserWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 6;
     
        series1 = "CM";
        series2 = "Color LaserJet";
        series3 = "LaserJet";
        series4 = "LaserJet Enterprise";
        series5 = "LaserJet Pro";
        series6 = "Mopier";
     
        SetSeriesInfos();
    }
     
    void MainWindow::LexmarkInkWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 19;
     
        series1 = "Color Jet Printer";
        series2 = "Genesis";
        series3 = "Impact";
        series4 = "Interact";
        series5 = "Interpret";
        series6 = "Intuition";
        series7 = "Jet Printer I";
        series8 = "Jet Printer P";
        series9 = "Jet Printer X";
        series10 = "Jet Printer Z";
        series11 = "OfficeEdge";
        series12 = "Optra Color";
        series13 = "Pinnacle";
        series14 = "Platinum";
        series15 = "Prestige";
        series16 = "Prevail";
        series17 = "Pro";
        series18 = "Prospect";
        series19 = "S";
     
        SetSeriesInfos();
    }
     
    void MainWindow::LexmarkLaserWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 19;
     
        series1 = "CS";
        series2 = "MS";
        series3 = "MX";
        series4 = "Optra-C";
        series5 = "Optra-Color";
        series6 = "Optra-E";
        series7 = "Optra-Image";
        series8 = "Optra-K";
        series9 = "Optra-L";
        series10 = "Optra-M";
        series11 = "Optra-R";
        series12 = "Optra-S";
        series13 = "Optra-SC";
        series14 = "Optra-SE";
        series15 = "Optra-T";
        series16 = "Optra-W";
        series17 = "Optra-X";
        series18 = "Pennant Systems IBM";
        series19 = "3000";
     
        SetSeriesInfos();
    }
     
    void MainWindow::SamsungInkWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 8;
     
        series1 = "CJX";
        series2 = "FX";
        series3 = "Msys";
        series4 = "MultiJet";
        series5 = "MyJet";
        series6 = "SCX";
        series7 = "SF";
        series8 = "SmartJet";
     
        SetSeriesInfos();
    }
     
    void MainWindow::SamsungLaserWindow()
    {
        HideTypeButtons();
     
        seriesNumber = 11;
     
        series1 = "CLP";
        series2 = "CLX";
        series3 = "IZZI";
        series4 = "ML";
        series5 = "MSYS";
        series6 = "MultiXpress";
        series7 = "ProXpress";
        series8 = "QWICKLASER";
        series9 = "SCX";
        series10 = "SF";
        series11 = "SL";
     
        SetSeriesInfos();
    }
     
    //############### Private slots ###############
    void MainWindow::HomeWindow()
    {
        HideTypeButtons();
        HideSeriesButtons();
     
        markPic->hide();
        exitButton->hide();
        nextSeriesButton->hide();
        previousSeriesButton->hide();
     
        brotherButton->show();
        canonButton->show();
        epsonButton->show();
        hpButton->show();
        lexmarkButton->show();
        samsungButton->show();
    }
     
    void MainWindow::runBrother()
    {
        myMark = "brother";
        TypeWindow();
    }
     
    void MainWindow::runCanon()
    {
        myMark = "canon";
        TypeWindow();
    }
     
    void MainWindow::runEpson()
    {
        myMark = "epson";
        TypeWindow();
    }
     
    void MainWindow::runHp()
    {
        myMark = "hp";
        TypeWindow();
    }
     
    void MainWindow::runLexmark()
    {
        myMark = "lexmark";
        TypeWindow();
    }
     
    void MainWindow::runSamsung()
    {
        myMark = "samsung";
        TypeWindow();
    }
     
    void MainWindow::InkClicked()
    {
        myPage = 1;
        if (myMark == "brother")
            BrotherInkWindow();
        else if (myMark == "canon")
            CanonInkWindow();
        else if (myMark == "epson")
            EpsonInkWindow();
        else if (myMark == "hp")
            HPInkWindow();
        else if (myMark == "lexmark")
            LexmarkInkWindow();
        else if (myMark == "samsung")
            SamsungInkWindow();
    }
     
    void MainWindow::LaserClicked()
    {
        myPage = 1;
        if (myMark == "brother")
            BrotherLaserWindow();
        else if (myMark == "canon")
            CanonLaserWindow();
        else if (myMark == "epson")
            EpsonLaserWindow();
        else if (myMark == "hp")
            HPLaserWindow();
        else if (myMark == "lexmark")
            LexmarkLaserWindow();
        else if (myMark == "samsung")
            SamsungLaserWindow();
    }
     
    void MainWindow::NextSeriesButtonClicked()
    {
        myPage++;
        SetSeriesInfos();
    }
     
    void MainWindow::PreviousSeriesButtonClicked()
    {
        myPage--;
        SetSeriesInfos();
    }
    A cet instant, le passage sur l'assignation des valeurs aux boutons est assez lourd. Je vais le remplacer par un fichier .txt (comme pour ma base de données) contenant les valeurs des boutons et j'ajouterai une (ou des) boucle(s) pour assigner les valeurs aux boutons à partir du .txt

  6. #6
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 577
    Points
    218 577
    Billets dans le blog
    120
    Par défaut
    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
    std::string series1;
    std::string series2;
    std::string series3;
    std::string series4;
    std::string series5;
    std::string series6;
    std::string series7;
    std::string series8;
    std::string series9;
    std::string series10;
    std::string series11;
    std::string series12;
    std::string series13;
    std::string series14;
    std::string series15;
    std::string series16;
    std::string series17;
    std::string series18;
    std::string series19;
    std::string series20;
    std::string series21;
    std::string series22;
    Tableauuuuu !!!!!
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  7. #7
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    J'ai mis des tableaux... enfin des vector et QVector, ayant des nombres de données variables à stocker c'est plus souple.

    En revanche un nouveau problème est apparu...

    Quand j'exécute mon application (au point où elle en est), je clique sur un bouton de marque, j'arrive sur la page de sélection encre/laser, je clique sur l'un des 2, j'arrive sur la page de sélection des séries. Jusque là tout va bien.

    En revanche, dès que j'appuie sur le bouton Home, je reviens bien au départ, je suis de nouveau le même chemin, mais j'ai bon changer de marque et/ou de type (encre/laser), les boutons de sélection des familles sont les mêmes.

    Par conte si je quitte mon application et l'exécute à nouveau. Si je choisi une autre marque et/ou type, j'ai bien les bonnes infos, mais si je reprends au début pour choisir autre chose, pareil... les boutons de choix de séries restent les même.

    J'ai essayé d'ajouter une ligne pour nettoyer ma table de séries ( seriesTable.clear() ) à chaque fois que je clique sur le bouton Home, mais là c'est pire car dès que je choisi un autre chemin le programme plante.

    J'en déduis que la première fois les données sont bien lues et attribuées depuis ma base de données .txt mais que dès que je change de chemin elles ne sont plus relues et ré-attribuées. Donc cela explique le plantage quand j'ai ajouté le 'clear' car du coup le programme essayait de manipuler des données qui n'existaient plus.

    Malheureusement je n'arrive pas à savoir d'où cela vient.

    Voici mon code actuel :

    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
    #include <QApplication>
     
    #include "MainWindow.h"
     
     
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
     
        MainWindow window;
        window.show();
     
        return app.exec();
    }
    MainWindow.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
    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
    #ifndef MAINWINDOW
    #define MAINWINDOW
     
    #include <QtWidgets>
    #include <vector>
    #include <QVector>
    #include <fstream>
    #include "Init.h"
     
    class MainWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        MainWindow();
     
        private slots:
        void HomeWindow();
        void runBrother();
        void runCanon();
        void runEpson();
        void runHp();
        void runLexmark();
        void runSamsung();
        void InkClicked();
        void LaserClicked();
        void NextSeriesButtonClicked();
        void PreviousSeriesButtonClicked();
     
        private:
        std::vector<std::string> seriesTable;
        QVector<QPushButton*> markButton;
        QVector<QPushButton*> seriesButton;
     
        std::ifstream file;
        int myPage;
        int seriesNumber;
        int pageNumber;
        std::string myMark;
     
        QPushButton *inkButton;
        QPushButton *laserButton;
     
        QPushButton *markPic;
        QPushButton *logo;
        QPushButton *nextSeriesButton;
        QPushButton *previousSeriesButton;
        QPushButton *exitButton;
     
        std::string ReadInfos(std::ifstream &file);
        void SearchSeries(std::ifstream &file, std::vector<std::string> &table, std::string series);
        void AssignSeries(std::ifstream &file, std::vector<std::string> &table);
     
        void TypeWindow();
        void HideTypeButtons();
        void HideSeriesButtons();
        void SetSeriesInfos();
        void ShowSeriesButton();
     
        void BrotherInkWindow();
        void BrotherLaserWindow();
        void CanonInkWindow();
        void CanonLaserWindow();
        void EpsonInkWindow();
        void EpsonLaserWindow();
        void HPInkWindow();
        void HPLaserWindow();
        void LexmarkInkWindow();
        void LexmarkLaserWindow();
        void SamsungInkWindow();
        void SamsungLaserWindow();
     
        void Button();
        void Slots();
    };
     
    #endif // MAINWINDOW
    MainWindow.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
    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
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    #include "MainWindow.h"
     
    MainWindow::MainWindow() : QWidget()
    {
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Ink Finder"));
     
        file.open("database.txt", std::ifstream::in);
     
        Button();
     
        Slots();
    }
     
    //############### Private functions ###############
    void MainWindow::Button()
    {
        //###########################################################
        //############## Mark chooser window's buttons ##############
        //###########################################################
     
        for (int n = 0; n < 6; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::MARK_COL_1;
            else
                x = Init::MARK_COL_2;
     
            if (n < 2)
                y = Init::MARK_LIN_1;
            else if (n < 4)
                y = Init::MARK_LIN_2;
            else if (n < 6)
                y = Init::MARK_LIN_3;
     
            //Setting button's attributes
            markButton.push_back(new QPushButton(this));
            markButton[n]->setIcon(QIcon(QString::fromStdString("pictures/" + ReadInfos(file) + ".png")));
            markButton[n]->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
            markButton[n]->setFlat(true);
            markButton[n]->setGeometry(x, y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        }
     
        //###########################################################
        //############## Type chooser window's buttons ##############
        //###########################################################
     
        inkButton = new QPushButton("Jet d'encre", this);
        inkButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_1, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        inkButton->setFont(Init::FONT1);
        inkButton->hide();
     
        laserButton = new QPushButton("Laser", this);
        laserButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_2, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        laserButton->setFont(Init::FONT1);
        laserButton->hide();
     
        //###########################################################
        //############# Series chooser window's buttons #############
        //###########################################################
     
        for (int n = 0; n < 10; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::HOME_COL_1;
            else
                x = Init::HOME_COL_2;
     
            if (n <= 1)
                y = Init::HOME_LIN_1;
            else if (n <= 3)
                y = Init::HOME_LIN_2;
            else if (n <= 5)
                y = Init::HOME_LIN_3;
            else if (n <= 7)
                y = Init::HOME_LIN_4;
            else if (n <= 9)
                y = Init::HOME_LIN_5;
     
            //Setting button's attributes
            seriesButton.push_back(new QPushButton(this));
            seriesButton[n]->setFont(Init::FONT6);
            seriesButton[n]->hide();
            seriesButton[n]->setGeometry(x, y, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        }
     
        //###########################################################
        //################# Common window's buttons #################
        //###########################################################
     
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        markPic = new QPushButton(this);
        markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->setFlat(true);
        markPic->hide();
     
        nextSeriesButton = new QPushButton(QIcon("pictures/next.png"), "", this);
        nextSeriesButton->setGeometry(Init::EXIT_X - 75, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        nextSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        nextSeriesButton->setFlat(true);
        nextSeriesButton->hide();
     
        previousSeriesButton = new QPushButton(QIcon("pictures/previous.png"), "", this);
        previousSeriesButton->setGeometry(Init::EXIT_X - 150, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        previousSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        previousSeriesButton->setFlat(true);
        previousSeriesButton->hide();
     
        exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
        exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        exitButton->hide();
    }
     
    void MainWindow::Slots()
    {
        connect(markButton[0], SIGNAL(clicked(bool)), this, SLOT(runBrother()));
        connect(markButton[1], SIGNAL(clicked(bool)), this, SLOT(runCanon()));
        connect(markButton[2], SIGNAL(clicked(bool)), this, SLOT(runEpson()));
        connect(markButton[3], SIGNAL(clicked(bool)), this, SLOT(runHp()));
        connect(markButton[4], SIGNAL(clicked(bool)), this, SLOT(runLexmark()));
        connect(markButton[5], SIGNAL(clicked(bool)), this, SLOT(runSamsung()));
        connect(exitButton, SIGNAL(clicked(bool)), this, SLOT(HomeWindow()));
        connect(nextSeriesButton, SIGNAL(clicked(bool)), this, SLOT(NextSeriesButtonClicked()));
        connect(previousSeriesButton, SIGNAL(clicked(bool)), this, SLOT(PreviousSeriesButtonClicked()));
        connect(inkButton, SIGNAL(clicked(bool)), this, SLOT(InkClicked()));
        connect(laserButton, SIGNAL(clicked(bool)), this, SLOT(LaserClicked()));
    }
     
    std::string MainWindow::ReadInfos(std::ifstream &file)
    {
        std::string word;
        file >> word;
        return word;
    }
     
    void MainWindow::SearchSeries(std::ifstream &file, std::vector<std::string> &table, std::string series)
    {
        std::string line;
        while(getline(file, line))
        {
            if(line == series)
            {
                AssignSeries(file, table);
            }
        }
    }
     
    void MainWindow::AssignSeries(std::ifstream &file, std::vector<std::string> &table)
    {
        std::string word = "";
        while (word != "end")
        {
            word = ReadInfos(file);
            if (word != "end")
                table.push_back(word);
        }
    }
     
    void MainWindow::TypeWindow()
    {
        markPic->setIcon(QIcon(QString::fromStdString("pictures/" + myMark + ".png")));
        markPic->show();
     
        //Hiding all mark buttons
        for (int n = 0; n < 6; n++)
            markButton[n]->hide();
     
        inkButton->show();
        laserButton->show();
     
        exitButton->show();
    }
     
    void MainWindow::HideTypeButtons()
    {
        inkButton->hide();
        laserButton->hide();
    }
     
    void MainWindow::HideSeriesButtons()
    {
        for (int n = 0; n < 10; n++)
            seriesButton[n]->hide();
    }
     
    void MainWindow::ShowSeriesButton()
    {
        HideSeriesButtons();
     
        //Calculating number of buttons to show
        int n = seriesNumber - (10 * (myPage - 1));
     
        //Showing buttons
        if (n >= 1)
            seriesButton[0]->show();
        if (n >= 2)
            seriesButton[1]->show();
        if (n >= 3)
            seriesButton[2]->show();
        if (n >= 4)
            seriesButton[3]->show();
        if (n >= 5)
            seriesButton[4]->show();
        if (n >= 6)
            seriesButton[5]->show();
        if (n >= 7)
            seriesButton[6]->show();
        if (n >= 8)
            seriesButton[7]->show();
        if (n >= 9)
            seriesButton[8]->show();
        if (n >= 10)
            seriesButton[9]->show();
     
        //Showing 'next' and 'previous' as it's needed
        if (myPage == 1)
        {
            if (pageNumber > 1)
                nextSeriesButton->show();
            else
                nextSeriesButton->hide();
     
            previousSeriesButton->hide();
        }
        if (myPage == pageNumber && pageNumber > 1)
        {
            nextSeriesButton->hide();
            previousSeriesButton->show();
        }
        if (myPage > 1 && myPage < pageNumber)
        {
            nextSeriesButton->show();
            previousSeriesButton->show();
        }
    }
     
    void MainWindow::SetSeriesInfos()
    {
        int max, n;
     
        //Calculating number of pages
        pageNumber = seriesNumber / 10;
     
        //Calculating number of series to show
        if ((seriesNumber % 10) != 0)
            pageNumber++;
     
        if (myPage == pageNumber)
        {
            if (seriesNumber % 10 == 0)
                max = 10;
            else
                max = seriesNumber % 10;
        }
        else if (myPage < pageNumber)
            max = 10;
     
        //Setting text to button
        for (n = 0; n < max; n++)
            seriesButton[n]->setText(QString::fromStdString(seriesTable[n + (10 * (myPage - 1))]));
     
        ShowSeriesButton();
    }
     
    void MainWindow::BrotherInkWindow()
    {    
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "BrotherInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::BrotherLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "BrotherLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::CanonInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "CanonInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::CanonLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "CanonLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::EpsonInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "EpsonInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::EpsonLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "EpsonLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::HPInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "HPInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::HPLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "HPLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::LexmarkInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "LexmarkInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::LexmarkLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "LexmarkLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::SamsungInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "SamsungInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::SamsungLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "SamsungLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    //############### Private slots ###############
    void MainWindow::HomeWindow()
    {
        HideTypeButtons();
        HideSeriesButtons();
     
        markPic->hide();
        exitButton->hide();
        nextSeriesButton->hide();
        previousSeriesButton->hide();
     
        for (int n = 0; n < markButton.size(); n++)
            markButton[n]->show();
    }
     
    void MainWindow::runBrother()
    {
        myMark = "brother";
        TypeWindow();
    }
     
    void MainWindow::runCanon()
    {
        myMark = "canon";
        TypeWindow();
    }
     
    void MainWindow::runEpson()
    {
        myMark = "epson";
        TypeWindow();
    }
     
    void MainWindow::runHp()
    {
        myMark = "hp";
        TypeWindow();
    }
     
    void MainWindow::runLexmark()
    {
        myMark = "lexmark";
        TypeWindow();
    }
     
    void MainWindow::runSamsung()
    {
        myMark = "samsung";
        TypeWindow();
    }
     
    void MainWindow::InkClicked()
    {
        myPage = 1;
        if (myMark == "brother")
            BrotherInkWindow();
        else if (myMark == "canon")
            CanonInkWindow();
        else if (myMark == "epson")
            EpsonInkWindow();
        else if (myMark == "hp")
            HPInkWindow();
        else if (myMark == "lexmark")
            LexmarkInkWindow();
        else if (myMark == "samsung")
            SamsungInkWindow();
    }
     
    void MainWindow::LaserClicked()
    {
        myPage = 1;
        if (myMark == "brother")
            BrotherLaserWindow();
        else if (myMark == "canon")
            CanonLaserWindow();
        else if (myMark == "epson")
            EpsonLaserWindow();
        else if (myMark == "hp")
            HPLaserWindow();
        else if (myMark == "lexmark")
            LexmarkLaserWindow();
        else if (myMark == "samsung")
            SamsungLaserWindow();
    }
     
    void MainWindow::NextSeriesButtonClicked()
    {
        myPage++;
        SetSeriesInfos();
    }
     
    void MainWindow::PreviousSeriesButtonClicked()
    {
        myPage--;
        SetSeriesInfos();
    }

  8. #8
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 577
    Points
    218 577
    Billets dans le blog
    120
    Par défaut
    J'ai essayé d'ajouter une ligne pour nettoyer ma table de séries ( seriesTable.clear() ) à chaque fois que je clique sur le bouton Home, mais là c'est pire car dès que je choisi un autre chemin le programme plante.
    Il faut comprendre la raison de ce plantage.

    Pour cela, vous pouvez utiliser un débogueur.

    Vous pouvez factoriser ce code :
    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
    void MainWindow::runBrother()
    {
        myMark = "brother";
        TypeWindow();
    }
     
    void MainWindow::runCanon()
    {
        myMark = "canon";
        TypeWindow();
    }
     
    void MainWindow::runEpson()
    {
        myMark = "epson";
        TypeWindow();
    }
     
    void MainWindow::runHp()
    {
        myMark = "hp";
        TypeWindow();
    }
     
    void MainWindow::runLexmark()
    {
        myMark = "lexmark";
        TypeWindow();
    }
     
    void MainWindow::runSamsung()
    {
        myMark = "samsung";
        TypeWindow();
    }
    Notamment en utilisant un paramètre qui indiquerait la marque de l'imprimante.
    Pareil ici :
    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
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    void MainWindow::BrotherInkWindow()
    {    
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "BrotherInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::BrotherLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "BrotherLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::CanonInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "CanonInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::CanonLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "CanonLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::EpsonInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "EpsonInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::EpsonLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "EpsonLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::HPInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "HPInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::HPLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "HPLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::LexmarkInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "LexmarkInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::LexmarkLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "LexmarkLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::SamsungInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "SamsungInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::SamsungLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "SamsungLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
    Cela peur se simplifier :
    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
    //Showing buttons
        if (n >= 1)
            seriesButton[0]->show();
        if (n >= 2)
            seriesButton[1]->show();
        if (n >= 3)
            seriesButton[2]->show();
        if (n >= 4)
            seriesButton[3]->show();
        if (n >= 5)
            seriesButton[4]->show();
        if (n >= 6)
            seriesButton[5]->show();
        if (n >= 7)
            seriesButton[6]->show();
        if (n >= 8)
            seriesButton[7]->show();
        if (n >= 9)
            seriesButton[8]->show();
        if (n >= 10)
            seriesButton[9]->show();
    Notamment, on dirait que l'indice du tableau, ce n'est que "n - 1"

    Je sais que je peux paraitre pénible (ou que je suis pénible). Mais la réalité, c'est qu'un code simple est beaucoup moins sujet aux bogues. Mais que en plus, il est plus facile à déboguer et à corriger. Et finalement, il me sera plus facile de relire un code simple, qu'un code compliqué. Surtout lorsque ce code n'est pas commenté et que vous ne dites pas où le bogue pourrait être.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  9. #9
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    LittleWhite, encore une fois merci pour ces indications qui m'ont été très précieuses.

    Déjà pour alléger et simplifier mon code, et ensuite car cela m'a permis de régler le problème des données qui ne "s'actualisaient" pas quand je revenais en arrière pour faire d'autres choix.

    Le fait d'avoir factorisé ce passage du code m'a permis de régler mon problème :
    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
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    void MainWindow::BrotherInkWindow()
    {    
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "BrotherInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::BrotherLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "BrotherLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::CanonInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "CanonInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::CanonLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "CanonLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::EpsonInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "EpsonInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::EpsonLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "EpsonLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::HPInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "HPInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::HPLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "HPLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::LexmarkInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "LexmarkInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::LexmarkLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "LexmarkLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::SamsungInkWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "SamsungInk");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::SamsungLaserWindow()
    {
        HideTypeButtons();
     
        SearchSeries(file, seriesTable, "SamsungLaser");
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
    Maintenant pour chacune de ces fonctions je n'ai plus que la même chose que celle-ci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    void MainWindow::BrotherInkWindow()
    {    
        SeriesWindowGeneration("BrotherInk");
    }
    Et la nouvelle fonction créée est la suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    void MainWindow::SeriesWindowGeneration(std::string series)
    {
        seriesTable.clear();
     
        HideTypeButtons();
     
        std::ifstream file("database.txt", std::ifstream::in);
        SearchSeries(file, seriesTable, series);
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
    Initialement j'avais déclaré mon 'std::ifstream file' dans le header et je l'initialisais en faisant 'file.open("database.txt", std::ifstream::in)' dans mon constructeur. Malhereusement à cause de ceci quand je revenais en arrière pour faire d'autres choix, mon flux étant alors fermé, les données ne s'actualisaient plus car impossible de lire les nouvelles.
    J'ai donc supprimé la déclaration de mon ifstream dans le header, et je le déclare et l'initialise en même temps avant chaque utilisation.
    C'est ce qui a réglé mon problème.

    Le 'seriesTable.clear()' qui vide cette table, m'évite alors que les nouvelles données suite à mon nouveau choix ne s'ajoutent aux précédentes (j'aurai au moins anticipé cette erreur ).

    Voici donc mon MainWindow.cpp dans son intégralité (du moins à ce niveau de refonte)
    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
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    #include "MainWindow.h"
     
    MainWindow::MainWindow() : QWidget()
    {
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Ink Finder"));
     
        Button();
     
        Slots();
    }
     
    //############### Private functions ###############
    void MainWindow::Button()
    {
        //###########################################################
        //############## Mark chooser window's buttons ##############
        //###########################################################
     
        std::ifstream file("database.txt", std::ifstream::in);
     
        for (int n = 0; n < 6; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::MARK_COL_1;
            else
                x = Init::MARK_COL_2;
     
            if (n < 2)
                y = Init::MARK_LIN_1;
            else if (n < 4)
                y = Init::MARK_LIN_2;
            else if (n < 6)
                y = Init::MARK_LIN_3;
     
            //Setting button's attributes
            markButton.push_back(new QPushButton(this));
            markButton[n]->setIcon(QIcon(QString::fromStdString("pictures/" + ReadInfos(file) + ".png")));
            markButton[n]->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
            markButton[n]->setFlat(true);
            markButton[n]->setGeometry(x, y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        }
     
        //###########################################################
        //############## Type chooser window's buttons ##############
        //###########################################################
     
        inkButton = new QPushButton("Jet d'encre", this);
        inkButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_1, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        inkButton->setFont(Init::FONT1);
        inkButton->hide();
     
        laserButton = new QPushButton("Laser", this);
        laserButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_2, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        laserButton->setFont(Init::FONT1);
        laserButton->hide();
     
        //###########################################################
        //############# Series chooser window's buttons #############
        //###########################################################
     
        for (int n = 0; n < 10; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::HOME_COL_1;
            else
                x = Init::HOME_COL_2;
     
            if (n <= 1)
                y = Init::HOME_LIN_1;
            else if (n <= 3)
                y = Init::HOME_LIN_2;
            else if (n <= 5)
                y = Init::HOME_LIN_3;
            else if (n <= 7)
                y = Init::HOME_LIN_4;
            else if (n <= 9)
                y = Init::HOME_LIN_5;
     
            //Setting button's attributes
            seriesButton.push_back(new QPushButton(this));
            seriesButton[n]->setFont(Init::FONT6);
            seriesButton[n]->hide();
            seriesButton[n]->setGeometry(x, y, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        }
     
        //###########################################################
        //################# Common window's buttons #################
        //###########################################################
     
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        markPic = new QPushButton(this);
        markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->setFlat(true);
        markPic->hide();
     
        nextSeriesButton = new QPushButton(QIcon("pictures/next.png"), "", this);
        nextSeriesButton->setGeometry(Init::EXIT_X - 75, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        nextSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        nextSeriesButton->setFlat(true);
        nextSeriesButton->hide();
     
        previousSeriesButton = new QPushButton(QIcon("pictures/previous.png"), "", this);
        previousSeriesButton->setGeometry(Init::EXIT_X - 150, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        previousSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        previousSeriesButton->setFlat(true);
        previousSeriesButton->hide();
     
        exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
        exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        exitButton->hide();
    }
     
    void MainWindow::Slots()
    {
        connect(markButton[0], SIGNAL(clicked(bool)), this, SLOT(runBrother()));
        connect(markButton[1], SIGNAL(clicked(bool)), this, SLOT(runCanon()));
        connect(markButton[2], SIGNAL(clicked(bool)), this, SLOT(runEpson()));
        connect(markButton[3], SIGNAL(clicked(bool)), this, SLOT(runHp()));
        connect(markButton[4], SIGNAL(clicked(bool)), this, SLOT(runLexmark()));
        connect(markButton[5], SIGNAL(clicked(bool)), this, SLOT(runSamsung()));
        connect(exitButton, SIGNAL(clicked(bool)), this, SLOT(HomeWindow()));
        connect(nextSeriesButton, SIGNAL(clicked(bool)), this, SLOT(NextSeriesButtonClicked()));
        connect(previousSeriesButton, SIGNAL(clicked(bool)), this, SLOT(PreviousSeriesButtonClicked()));
        connect(inkButton, SIGNAL(clicked(bool)), this, SLOT(InkClicked()));
        connect(laserButton, SIGNAL(clicked(bool)), this, SLOT(LaserClicked()));
    }
     
    std::string MainWindow::ReadInfos(std::ifstream &database)
    {
        std::string word;
        database >> word;
        return word;
    }
     
    void MainWindow::SearchSeries(std::ifstream &database, std::vector<std::string> &table, std::string series)
    {
        std::string line;
        while(getline(database, line))
        {
            if(line == series)
            {
                AssignSeries(database, table);
            }
        }
    }
     
    void MainWindow::AssignSeries(std::ifstream &database, std::vector<std::string> &table)
    {
        std::string word = "";
        while (word != "end")
        {
            word = ReadInfos(database);
            if (word != "end")
                table.push_back(word);
        }
    }
     
    void MainWindow::TypeWindow(std::string mark)
    {
        myMark = mark;
        markPic->setIcon(QIcon(QString::fromStdString("pictures/" + myMark + ".png")));
        markPic->show();
     
        //Hiding all mark buttons
        for (int n = 0; n < 6; n++)
            markButton[n]->hide();
     
        inkButton->show();
        laserButton->show();
     
        exitButton->show();
    }
     
    void MainWindow::HideTypeButtons()
    {
        inkButton->hide();
        laserButton->hide();
    }
     
    void MainWindow::HideSeriesButtons()
    {
        for (int n = 0; n < 10; n++)
            seriesButton[n]->hide();
    }
     
    void MainWindow::ShowSeriesButton(int number)
    {
        HideSeriesButtons();
     
        //Showing buttons
        for (int i = 0; i < number; i++)
            seriesButton[i]->show();
     
        //Showing 'next' and 'previous' as it's needed
        if (myPage == 1)
        {
            if (pageNumber > 1)
                nextSeriesButton->show();
            else
                nextSeriesButton->hide();
     
            previousSeriesButton->hide();
        }
        if (myPage == pageNumber && pageNumber > 1)
        {
            nextSeriesButton->hide();
            previousSeriesButton->show();
        }
        if (myPage > 1 && myPage < pageNumber)
        {
            nextSeriesButton->show();
            previousSeriesButton->show();
        }
    }
     
    void MainWindow::SeriesWindowGeneration(std::string series)
    {
        seriesTable.clear();
     
        HideTypeButtons();
     
        std::ifstream file2("database.txt", std::ifstream::in);
        SearchSeries(file2, seriesTable, series);
     
        seriesNumber = seriesTable.size();
     
        SetSeriesInfos();
    }
     
    void MainWindow::SetSeriesInfos()
    {
        int max, n;
     
        //Calculating number of pages
        pageNumber = seriesNumber / 10;
     
        //Calculating number of series to show
        if ((seriesNumber % 10) != 0)
            pageNumber++;
     
        if (myPage == pageNumber)
        {
            if (seriesNumber % 10 == 0)
                max = 10;
            else
                max = seriesNumber % 10;
        }
        else if (myPage < pageNumber)
            max = 10;
     
        //Setting text to button
        for (n = 0; n < max; n++)
            seriesButton[n]->setText(QString::fromStdString(seriesTable[n + (10 * (myPage - 1))]));
     
        ShowSeriesButton(max);
    }
     
    void MainWindow::BrotherInkWindow()
    {    
        SeriesWindowGeneration("BrotherInk");
    }
     
    void MainWindow::BrotherLaserWindow()
    {
        SeriesWindowGeneration("BrotherLaser");
    }
     
    void MainWindow::CanonInkWindow()
    {
        SeriesWindowGeneration("CanonInk");
    }
     
    void MainWindow::CanonLaserWindow()
    {
        SeriesWindowGeneration("CanonLaser");
    }
     
    void MainWindow::EpsonInkWindow()
    {
        SeriesWindowGeneration("EpsonInk");
    }
     
    void MainWindow::EpsonLaserWindow()
    {
        SeriesWindowGeneration("EpsonLaser");
    }
     
    void MainWindow::HPInkWindow()
    {
        SeriesWindowGeneration("HPInk");
    }
     
    void MainWindow::HPLaserWindow()
    {
        SeriesWindowGeneration("HPLaser");
    }
     
    void MainWindow::LexmarkInkWindow()
    {
        SeriesWindowGeneration("LexmarkInk");
    }
     
    void MainWindow::LexmarkLaserWindow()
    {
        SeriesWindowGeneration("LexmarkLaser");
    }
     
    void MainWindow::SamsungInkWindow()
    {
        SeriesWindowGeneration("SamsungInk");
    }
     
    void MainWindow::SamsungLaserWindow()
    {
        SeriesWindowGeneration("SamsungLaser");
    }
     
    //############### Private slots ###############
    void MainWindow::HomeWindow()
    {
        HideTypeButtons();
        HideSeriesButtons();
     
        markPic->hide();
        exitButton->hide();
        nextSeriesButton->hide();
        previousSeriesButton->hide();
     
        for (int n = 0; n < markButton.size(); n++)
            markButton[n]->show();
    }
     
    void MainWindow::runBrother()
    {
        TypeWindow("brother");
    }
     
    void MainWindow::runCanon()
    {
        TypeWindow("canon");
    }
     
    void MainWindow::runEpson()
    {
        TypeWindow("epson");
    }
     
    void MainWindow::runHp()
    {
        TypeWindow("hp");
    }
     
    void MainWindow::runLexmark()
    {
        TypeWindow("lexmark");
    }
     
    void MainWindow::runSamsung()
    {
        TypeWindow("samsung");
    }
     
    void MainWindow::InkClicked()
    {
        myPage = 1;
        if (myMark == "brother")
            BrotherInkWindow();
        else if (myMark == "canon")
            CanonInkWindow();
        else if (myMark == "epson")
            EpsonInkWindow();
        else if (myMark == "hp")
            HPInkWindow();
        else if (myMark == "lexmark")
            LexmarkInkWindow();
        else if (myMark == "samsung")
            SamsungInkWindow();
    }
     
    void MainWindow::LaserClicked()
    {
        myPage = 1;
        if (myMark == "brother")
            BrotherLaserWindow();
        else if (myMark == "canon")
            CanonLaserWindow();
        else if (myMark == "epson")
            EpsonLaserWindow();
        else if (myMark == "hp")
            HPLaserWindow();
        else if (myMark == "lexmark")
            LexmarkLaserWindow();
        else if (myMark == "samsung")
            SamsungLaserWindow();
    }
     
    void MainWindow::NextSeriesButtonClicked()
    {
        myPage++;
        SetSeriesInfos();
    }
     
    void MainWindow::PreviousSeriesButtonClicked()
    {
        myPage--;
        SetSeriesInfos();
    }
    Au passage, ce bout de code
    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
    //Showing buttons
        if (n >= 1)
            seriesButton[0]->show();
        if (n >= 2)
            seriesButton[1]->show();
        if (n >= 3)
            seriesButton[2]->show();
        if (n >= 4)
            seriesButton[3]->show();
        if (n >= 5)
            seriesButton[4]->show();
        if (n >= 6)
            seriesButton[5]->show();
        if (n >= 7)
            seriesButton[6]->show();
        if (n >= 8)
            seriesButton[7]->show();
        if (n >= 9)
            seriesButton[8]->show();
        if (n >= 10)
            seriesButton[9]->show();
    où 'n' était le résultat du calcule du nombre de bouton à afficher sur la page.

    Ce passage est devenu
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    for (int i = 0; i < number; i++)
            seriesButton[i]->show();
    Dans la fonction dans laquelle il est utilisé, je récupère en paramètre 'number' qui est le nombre de bouton à afficher sur la page et que je calcule déjà dans la fonction appelant celle-ci.

    P.S. : En ce qui concerne le côté pénible, je me l'attribue car je m'entête à garder ma "logique" qui n'est en fait pas simple (ça se voit à mon code). En aucun cas vous êtes pénible, car vous passez du temps à lire mon code "pas très organisé", à m'aider, me donner des indications et règles qui me permettent d'avancer, mieux m'organiser et régler des problèmes. Donc MERCI !

  10. #10
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 577
    Points
    218 577
    Billets dans le blog
    120
    Par défaut
    Initialement j'avais déclaré mon 'std::ifstream file' dans le header et je l'initialisais en faisant 'file.open("database.txt", std::ifstream::in)' dans mon constructeur. Malhereusement à cause de ceci quand je revenais en arrière pour faire d'autres choix, mon flux étant alors fermé, les données ne s'actualisaient plus car impossible de lire les nouvelles.
    En théorie, il faudrait éviter la lecture répétée du fichier, qui est une opération lente. Il est préférable de tenter de garder son contenu en mémoire (sauf s'il est trop imposant).

    garder ma "logique" qui n'est en fait pas simple (ça se voit à mon code)
    Un des bons conseils en programmation : diviser le gros problème en sous petits problèmes.
    C'est un peu comme les Lego (sauf que là, c'est à nous de faire les briques de base). Avec des briques de base (des fonctions simples et qui ne font qu'une seule chose à la fois), vous pouvez créer des maisons, des fusées, des machine à voyager dans le temps. Avec la programmation, c'est pareil. Il faut juste savoir décomposer un problème en d'autres petits problèmes simples.

    Encore une fois :
    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
    void MainWindow::BrotherInkWindow()
    {    
        SeriesWindowGeneration("BrotherInk");
    }
     
    void MainWindow::BrotherLaserWindow()
    {
        SeriesWindowGeneration("BrotherLaser");
    }
     
    void MainWindow::CanonInkWindow()
    {
        SeriesWindowGeneration("CanonInk");
    }
     
    void MainWindow::CanonLaserWindow()
    {
        SeriesWindowGeneration("CanonLaser");
    }
     
    void MainWindow::EpsonInkWindow()
    {
        SeriesWindowGeneration("EpsonInk");
    }
     
    void MainWindow::EpsonLaserWindow()
    {
        SeriesWindowGeneration("EpsonLaser");
    }
     
    void MainWindow::HPInkWindow()
    {
        SeriesWindowGeneration("HPInk");
    }
     
    void MainWindow::HPLaserWindow()
    {
        SeriesWindowGeneration("HPLaser");
    }
     
    void MainWindow::LexmarkInkWindow()
    {
        SeriesWindowGeneration("LexmarkInk");
    }
     
    void MainWindow::LexmarkLaserWindow()
    {
        SeriesWindowGeneration("LexmarkLaser");
    }
     
    void MainWindow::SamsungInkWindow()
    {
        SeriesWindowGeneration("SamsungInk");
    }
     
    void MainWindow::SamsungLaserWindow()
    {
        SeriesWindowGeneration("SamsungLaser");
    }
    Cela pourrait être transformée en une unique fonction qui prend un paramètre. En réalité, il y a une astuce avec les slots, c'est que l'on peux passer des paramètres au moment du connect.

    Pareil pour runXXX().

    D'ailleurs, ma simplification permettra de simplifier ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    if (myMark == "brother")
            BrotherLaserWindow();
        else if (myMark == "canon")
            CanonLaserWindow();
        else if (myMark == "epson")
            EpsonLaserWindow();
        else if (myMark == "hp")
            HPLaserWindow();
        else if (myMark == "lexmark")
            LexmarkLaserWindow();
        else if (myMark == "samsung")
            SamsungLaserWindow();
    En simplifiant tout ça, il vous sera genre mille fois plus facile d'ajouter une nouvelle imprimante/marque par la suite.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  11. #11
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Désolé d'avoir mis un peu de temps à poster ma réponse, mais je fais quelques travaux chez moi entre deux.

    J'ai donc replacé
    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
    void MainWindow::BrotherInkWindow()
    {    
        SeriesWindowGeneration("BrotherInk");
    }
     
    void MainWindow::BrotherLaserWindow()
    {
        SeriesWindowGeneration("BrotherLaser");
    }
     
    void MainWindow::CanonInkWindow()
    {
        SeriesWindowGeneration("CanonInk");
    }
     
    void MainWindow::CanonLaserWindow()
    {
        SeriesWindowGeneration("CanonLaser");
    }
     
    void MainWindow::EpsonInkWindow()
    {
        SeriesWindowGeneration("EpsonInk");
    }
     
    void MainWindow::EpsonLaserWindow()
    {
        SeriesWindowGeneration("EpsonLaser");
    }
     
    void MainWindow::HPInkWindow()
    {
        SeriesWindowGeneration("HPInk");
    }
     
    void MainWindow::HPLaserWindow()
    {
        SeriesWindowGeneration("HPLaser");
    }
     
    void MainWindow::LexmarkInkWindow()
    {
        SeriesWindowGeneration("LexmarkInk");
    }
     
    void MainWindow::LexmarkLaserWindow()
    {
        SeriesWindowGeneration("LexmarkLaser");
    }
     
    void MainWindow::SamsungInkWindow()
    {
        SeriesWindowGeneration("SamsungInk");
    }
     
    void MainWindow::SamsungLaserWindow()
    {
        SeriesWindowGeneration("SamsungLaser");
    }
    et
    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
    void MainWindow::InkClicked()
    {
        myPage = 1;
        if (myMark == "brother")
            BrotherInkWindow();
        else if (myMark == "canon")
            CanonInkWindow();
        else if (myMark == "epson")
            EpsonInkWindow();
        else if (myMark == "hp")
            HPInkWindow();
        else if (myMark == "lexmark")
            LexmarkInkWindow();
        else if (myMark == "samsung")
            SamsungInkWindow();
    }
     
    void MainWindow::LaserClicked()
    {
        myPage = 1;
        if (myMark == "brother")
            BrotherLaserWindow();
        else if (myMark == "canon")
            CanonLaserWindow();
        else if (myMark == "epson")
            EpsonLaserWindow();
        else if (myMark == "hp")
            HPLaserWindow();
        else if (myMark == "lexmark")
            LexmarkLaserWindow();
        else if (myMark == "samsung")
            SamsungLaserWindow();
    }
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    void MainWindow::InkClicked()
    {
        SeriesWindowGeneration(myMark + "Ink");
    }
     
    void MainWindow::LaserClicked()
    {
        SeriesWindowGeneration(myMark + "Laser");
    }

  12. #12
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Après ces modifications (simplifications, optimisations...) pour lesquelles je vous remercie, j'obtiens
    MainWindow.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
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    #ifndef MAINWINDOW
    #define MAINWINDOW
     
    #include <QtWidgets>
    #include <vector>
    #include <QVector>
    #include <fstream>
    #include "Init.h"
     
    class MainWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        MainWindow();
     
        private slots:
        void HomeWindow();
        void runBrother();
        void runCanon();
        void runEpson();
        void runHP();
        void runLexmark();
        void runSamsung();
        void InkClicked();
        void LaserClicked();
        void NextSeriesButtonClicked();
        void PreviousSeriesButtonClicked();
     
        private:
        std::vector<std::string> seriesTable;
        QVector<QPushButton*> markButton;
        QVector<QPushButton*> seriesButton;
     
        int myPage;
        int pageNumber;
        std::string myMark;
     
        QPushButton *inkButton;
        QPushButton *laserButton;
     
        QPushButton *markPic;
        QPushButton *logo;
        QPushButton *nextSeriesButton;
        QPushButton *previousSeriesButton;
        QPushButton *exitButton;
     
        std::string ReadInfos(std::ifstream &file);
        void SearchSeries(std::ifstream &file, std::vector<std::string> &table, std::string series);
        void AssignSeries(std::ifstream &file, std::vector<std::string> &table);
     
        void TypeWindow(std::string mark);
        void HideTypeButtons();
        void HideSeriesButtons();
        void SetSeriesInfos();
        void ShowSeriesButton(int number);
        void SeriesWindowGeneration(std::string series);
     
        void Button();
        void Slots();
    };
     
    #endif // MAINWINDOW
    MainWindow.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
    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
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    #include "MainWindow.h"
     
    MainWindow::MainWindow() : QWidget()
    {
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Ink Finder"));
     
        Button();
     
        Slots();
    }
     
    //############### Private functions ###############
    void MainWindow::Button()
    {
        //###########################################################
        //############## Mark chooser window's buttons ##############
        //###########################################################
     
        std::ifstream file("database.txt", std::ifstream::in);
     
        for (int n = 0; n < 6; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::MARK_COL_1;
            else
                x = Init::MARK_COL_2;
     
            if (n < 2)
                y = Init::MARK_LIN_1;
            else if (n < 4)
                y = Init::MARK_LIN_2;
            else if (n < 6)
                y = Init::MARK_LIN_3;
     
            //Setting button's attributes
            markButton.push_back(new QPushButton(this));
            markButton[n]->setIcon(QIcon(QString::fromStdString("pictures/" + ReadInfos(file) + ".png")));
            markButton[n]->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
            markButton[n]->setFlat(true);
            markButton[n]->setGeometry(x, y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        }
     
        //###########################################################
        //############## Type chooser window's buttons ##############
        //###########################################################
     
        inkButton = new QPushButton("Jet d'encre", this);
        inkButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_1, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        inkButton->setFont(Init::FONT1);
        inkButton->hide();
     
        laserButton = new QPushButton("Laser", this);
        laserButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_2, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        laserButton->setFont(Init::FONT1);
        laserButton->hide();
     
        //###########################################################
        //############# Series chooser window's buttons #############
        //###########################################################
     
        for (int n = 0; n < 10; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::HOME_COL_1;
            else
                x = Init::HOME_COL_2;
     
            if (n <= 1)
                y = Init::HOME_LIN_1;
            else if (n <= 3)
                y = Init::HOME_LIN_2;
            else if (n <= 5)
                y = Init::HOME_LIN_3;
            else if (n <= 7)
                y = Init::HOME_LIN_4;
            else if (n <= 9)
                y = Init::HOME_LIN_5;
     
            //Setting button's attributes
            seriesButton.push_back(new QPushButton(this));
            seriesButton[n]->setFont(Init::FONT6);
            seriesButton[n]->hide();
            seriesButton[n]->setGeometry(x, y, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        }
     
        //###########################################################
        //################# Common window's buttons #################
        //###########################################################
     
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        markPic = new QPushButton(this);
        markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->setFlat(true);
        markPic->hide();
     
        nextSeriesButton = new QPushButton(QIcon("pictures/next.png"), "", this);
        nextSeriesButton->setGeometry(Init::EXIT_X - 75, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        nextSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        nextSeriesButton->setFlat(true);
        nextSeriesButton->hide();
     
        previousSeriesButton = new QPushButton(QIcon("pictures/previous.png"), "", this);
        previousSeriesButton->setGeometry(Init::EXIT_X - 150, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        previousSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        previousSeriesButton->setFlat(true);
        previousSeriesButton->hide();
     
        exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
        exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        exitButton->hide();
    }
     
    void MainWindow::Slots()
    {
        connect(markButton[0], SIGNAL(clicked(bool)), this, SLOT(runBrother()));
        connect(markButton[1], SIGNAL(clicked(bool)), this, SLOT(runCanon()));
        connect(markButton[2], SIGNAL(clicked(bool)), this, SLOT(runEpson()));
        connect(markButton[3], SIGNAL(clicked(bool)), this, SLOT(runHP()));
        connect(markButton[4], SIGNAL(clicked(bool)), this, SLOT(runLexmark()));
        connect(markButton[5], SIGNAL(clicked(bool)), this, SLOT(runSamsung()));
        connect(exitButton, SIGNAL(clicked(bool)), this, SLOT(HomeWindow()));
        connect(nextSeriesButton, SIGNAL(clicked(bool)), this, SLOT(NextSeriesButtonClicked()));
        connect(previousSeriesButton, SIGNAL(clicked(bool)), this, SLOT(PreviousSeriesButtonClicked()));
        connect(inkButton, SIGNAL(clicked(bool)), this, SLOT(InkClicked()));
        connect(laserButton, SIGNAL(clicked(bool)), this, SLOT(LaserClicked()));
    }
     
    //Function that read datas in the database file
    std::string MainWindow::ReadInfos(std::ifstream &database)
    {
        std::string word;
        database >> word;
        return word;
    }
     
    //Function that search datas in the database file
    void MainWindow::SearchSeries(std::ifstream &database, std::vector<std::string> &table, std::string series)
    {
        std::string line;
        while(getline(database, line))
        {
            if(line == series)
            {
                AssignSeries(database, table);
            }
        }
    }
     
    //Function that generates the series table from datas read from the database file
    void MainWindow::AssignSeries(std::ifstream &database, std::vector<std::string> &table)
    {
        std::string word = "";
        while (word != "end")
        {
            word = ReadInfos(database);
            if (word != "end")
                table.push_back(word);
        }
    }
     
    //Function that generates the Type window (to choose between ink and laser)
    void MainWindow::TypeWindow(std::string mark)
    {
        myMark = mark;
        markPic->setIcon(QIcon(QString::fromStdString("pictures/" + myMark + ".png")));
        markPic->show();
     
        //Hiding all mark buttons
        for (int n = 0; n < 6; n++)
            markButton[n]->hide();
     
        inkButton->show();
        laserButton->show();
     
        exitButton->show();
    }
     
    //Function that hides all type buttons
    void MainWindow::HideTypeButtons()
    {
        inkButton->hide();
        laserButton->hide();
    }
     
    //Function that hides all series buttons
    void MainWindow::HideSeriesButtons()
    {
        for (int n = 0; n < 10; n++)
            seriesButton[n]->hide();
    }
     
    //Function that determines which buttons to display
    void MainWindow::ShowSeriesButton(int number)
    {
        HideSeriesButtons();
     
        //Showing buttons
        for (int i = 0; i < number; i++)
            seriesButton[i]->show();
     
        //Showing 'next' and 'previous' as it's needed
        if (myPage == 1)
        {
            if (pageNumber > 1)
                nextSeriesButton->show();
            else
                nextSeriesButton->hide();
     
            previousSeriesButton->hide();
        }
        if (myPage == pageNumber && pageNumber > 1)
        {
            nextSeriesButton->hide();
            previousSeriesButton->show();
        }
        if (myPage > 1 && myPage < pageNumber)
        {
            nextSeriesButton->show();
            previousSeriesButton->show();
        }
    }
     
    //Function that generates the Series window (to choose between different series)
    void MainWindow::SeriesWindowGeneration(std::string series)
    {
        myPage = 1;
     
        //Resetting the table
        seriesTable.clear();
     
        HideTypeButtons();
     
        //Generating the table
        std::ifstream file("database.txt", std::ifstream::in);
        SearchSeries(file, seriesTable, series);
     
        SetSeriesInfos();
    }
     
    void MainWindow::SetSeriesInfos()
    {
        int max, n;
     
        //Calculating number of pages
        pageNumber = seriesTable.size() / 10;
     
        //Calculating number of series to show
        if ((seriesTable.size() % 10) != 0)
            pageNumber++;
     
        if (myPage == pageNumber)
        {
            if (seriesTable.size() % 10 == 0)
                max = 10;
            else
                max = seriesTable.size() % 10;
        }
        else if (myPage < pageNumber)
            max = 10;
     
        //Setting text to button
        for (n = 0; n < max; n++)
            seriesButton[n]->setText(QString::fromStdString(seriesTable[n + (10 * (myPage - 1))]));
     
        ShowSeriesButton(max);
    }
     
    //#############################################
    //############### Private slots ###############
    //#############################################
     
    //Slot that reset the actual window to the home window
    void MainWindow::HomeWindow()
    {
        HideTypeButtons();
        HideSeriesButtons();
     
        markPic->hide();
        exitButton->hide();
        nextSeriesButton->hide();
        previousSeriesButton->hide();
     
        for (int n = 0; n < markButton.size(); n++)
            markButton[n]->show();
    }
     
    //Slots that launch the function to generate the Type window by sending the mark
    void MainWindow::runBrother()
    {
        TypeWindow("brother");
    }
     
    void MainWindow::runCanon()
    {
        TypeWindow("canon");
    }
     
    void MainWindow::runEpson()
    {
        TypeWindow("epson");
    }
     
    void MainWindow::runHP()
    {
        TypeWindow("hp");
    }
     
    void MainWindow::runLexmark()
    {
        TypeWindow("lexmark");
    }
     
    void MainWindow::runSamsung()
    {
        TypeWindow("samsung");
    }
     
    //Slots that launch the right functions depending of the mark and the clicked button
    void MainWindow::InkClicked()
    {
        SeriesWindowGeneration(myMark + "Ink");
    }
     
    void MainWindow::LaserClicked()
    {
        SeriesWindowGeneration(myMark + "Laser");
    }
     
    //Slots that determines the next and previous button's actions
    void MainWindow::NextSeriesButtonClicked()
    {
        myPage++;
        SetSeriesInfos();
    }
     
    void MainWindow::PreviousSeriesButtonClicked()
    {
        myPage--;
        SetSeriesInfos();
    }
    Par rapport à mon premier post avec mon nouveau MainWindow.cpp (et .h) je suis passé de 662 lignes de code à 352...
    Tout ceci grâce à vous... MERCI !

  13. #13
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 577
    Points
    218 577
    Billets dans le blog
    120
    Par défaut
    J'avais fait la remarque pour deux morceaux de code répétés. Vous en avez corriger un, c'est bien. Il reste l'autre à corriger
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  14. #14
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Par "l'autre bout de code", vous entendez l'autre cité dans votre précédent post ?
    C'est-à-dire celui-ci
    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
    void MainWindow::BrotherInkWindow()
    {    
        SeriesWindowGeneration("BrotherInk");
    }
     
    void MainWindow::BrotherLaserWindow()
    {
        SeriesWindowGeneration("BrotherLaser");
    }
     
    void MainWindow::CanonInkWindow()
    {
        SeriesWindowGeneration("CanonInk");
    }
     
    void MainWindow::CanonLaserWindow()
    {
        SeriesWindowGeneration("CanonLaser");
    }
     
    void MainWindow::EpsonInkWindow()
    {
        SeriesWindowGeneration("EpsonInk");
    }
     
    void MainWindow::EpsonLaserWindow()
    {
        SeriesWindowGeneration("EpsonLaser");
    }
     
    void MainWindow::HPInkWindow()
    {
        SeriesWindowGeneration("HPInk");
    }
     
    void MainWindow::HPLaserWindow()
    {
        SeriesWindowGeneration("HPLaser");
    }
     
    void MainWindow::LexmarkInkWindow()
    {
        SeriesWindowGeneration("LexmarkInk");
    }
     
    void MainWindow::LexmarkLaserWindow()
    {
        SeriesWindowGeneration("LexmarkLaser");
    }
     
    void MainWindow::SamsungInkWindow()
    {
        SeriesWindowGeneration("SamsungInk");
    }
     
    void MainWindow::SamsungLaserWindow()
    {
        SeriesWindowGeneration("SamsungLaser");
    }
    Car si c'est le cas ce bout de code a été tout simplement supprimé, car la fonction appelée "SeriesWindowGeneration(std::string mark)" prenant en paramètre la marque + Ink ou Laser est maintenant directement appelée depuis les SLOT InkClicked et LaserClicked sous la forme "SeriesWindowGeneration(myMark + "Laser");" (ou + "Ink").
    Du coup, des 2 bouts de code de votre précédent post, je n'en ai fait qu'un de 9 lignes (accolades comprises)

  15. #15
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 577
    Points
    218 577
    Billets dans le blog
    120
    Par défaut
    Non, je parle d'un code qui est resté et que j'avais dit qu'il fallait aussi le simplifier :
    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
    //Slots that launch the function to generate the Type window by sending the mark
    void MainWindow::runBrother()
    {
        TypeWindow("brother");
    }
     
    void MainWindow::runCanon()
    {
        TypeWindow("canon");
    }
     
    void MainWindow::runEpson()
    {
        TypeWindow("epson");
    }
     
    void MainWindow::runHP()
    {
        TypeWindow("hp");
    }
     
    void MainWindow::runLexmark()
    {
        TypeWindow("lexmark");
    }
     
    void MainWindow::runSamsung()
    {
        TypeWindow("samsung");
    }
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  16. #16
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Ce bout de code regroupe mes SLOTS pour les boutons de choix de marque. Je vais donc devoir créer mon/mes propre(s) Signal(aux).

  17. #17
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 577
    Points
    218 577
    Billets dans le blog
    120
    Par défaut
    Je me cite, car c'était peut être pas clair, ou cela est passé à la trappe :
    Citation Envoyé par LittleWhite
    En réalité, il y a une astuce avec les slots, c'est que l'on peux passer des paramètres au moment du connect.
    Ce qui veut dire (pour être vraiment clair), que l'on peut écrire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    connect(this, SIGNAL(pushed()), this, SLOT("toto"))
    Bien entendu, le slot du coup, devra prendre un paramètre.

    Note : je ne suis pas sur à 100 % que cela marche, mais j'ai cru me rappeler que si. Il faut donc tester et voir.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  18. #18
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Ce qui veut dire (pour être vraiment clair), que l'on peut écrire :


    Code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    connect(this, SIGNAL(pushed()), this, SLOT("toto"))
    "this" est alors un pointeur vers ma fenêtre (QWidget), mais dans ce cas je ne trouve aucun signal "pushed()".

    La première fois que vous m'aviez parlé de ce passage en me parlant de passer un paramètre au moment du connect, j'avais essayé
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    connect(inkButton, SIGNAL(clicked(bool)), this, SLOT(InkClicked("Ink")));
    Mais malheureusement sans succès car du coup le bouton "inkButton" ne fonctionne plus. Vous aviez alors évoqué le QSignalMapper (qui m'est pour le moment inconnu), j'avais alors occulté ce passage .

    Cependant, d'après la documentation de Qt, je dois soit créer mes propres signaux, soit passer par un QSignalMapper.

    Reste maintenant à savoir lequel serait le plus adapté...

  19. #19
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 577
    Points
    218 577
    Billets dans le blog
    120
    Par défaut
    Mon code était du pseudo code juste pour montrer l'idée. On remarque qu'il y a plusieurs erreurs.

    Pour le fait que le bouton ne marchait plus, oui surement, mais j'aurais bien aimé voir le message d'erreur du signal/slot. Du coup, il faudra que je test.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  20. #20
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 858
    Points : 218 577
    Points
    218 577
    Billets dans le blog
    120
    Par défaut
    J'ai testé. En effet, il est obligatoire d'utiliser un QSignalMapper pour faire la simplification mentionnée.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. fuite de mémoire ?
    Par salseropom dans le forum C
    Réponses: 2
    Dernier message: 12/01/2006, 16h19
  2. Réponses: 1
    Dernier message: 02/12/2005, 14h18
  3. fuite de mémoire
    Par mamag dans le forum MFC
    Réponses: 17
    Dernier message: 19/08/2005, 10h42
  4. Fuite de mémoire en utilisant le template list
    Par schtroumpf_farceur dans le forum Langage
    Réponses: 9
    Dernier message: 18/07/2005, 20h44
  5. Réponses: 8
    Dernier message: 17/10/2002, 12h52

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