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

 C++ Discussion :

Passer une structure d'une classe vers une autre


Sujet :

C++

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    91
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 91
    Points : 96
    Points
    96
    Par défaut Passer une structure d'une classe vers une autre
    Bonjour,

    Je programme sous Qt6 (MinGW_64).

    Dans la class MainWindow j'ai différents objets tels que : (ayant leurs propres classes) :

    QWidget* entete = new head(contentWidget_01);
    QWidget* personnel = new navigants(contentWidget_10);

    Dans MainWindow j'ai une structure

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
        struct Personnel {
            QString nom[366];
            QString prenom[366];
            QString fonction[366];
            int joursDus[366];
        };
    Ca fait 24h que j'essaie de passer le contenu de cette structure à mes deux objets sans y parvenir.
    Quoique je fasse, j'ai toujours l'un des deux problèmes suivants :
    - la classe head:: ne connait pas "Personnel"
    - la classe head:: dit qu'il y a redéfinition de "Personnel"

    Pourriez-vous m'aider ?

    Merci.
    @+

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    1 116
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 116
    Points : 1 639
    Points
    1 639
    Par défaut
    Malheureusement, ma boule de cristal est cassée.

    Codes source stp.

  3. #3
    Modérateur

    Avatar de Bktero
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Juin 2009
    Messages
    4 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués

    Informations forums :
    Inscription : Juin 2009
    Messages : 4 481
    Points : 13 679
    Points
    13 679
    Billets dans le blog
    1
    Par défaut
    Il faut nous montrer plus de code pour comprendre ce que tu fais. Tu peux aussi nous montrer les messages d'erreurs de ton compilateur.

  4. #4
    Expert éminent sénior

    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    5 189
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Essonne (Île de France)

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

    Informations forums :
    Inscription : Juin 2007
    Messages : 5 189
    Points : 17 141
    Points
    17 141
    Par défaut
    A tous les coups, c'est une histoire de "forward declaration" et de passage par référence.

    Quoiqu'il en soit, pourquoi avoir mis 4 tableaux de la même taille et pas de nombre d'éléments utilisés, plutot qu'un joli std::vector d'une structure définissant une seule entrée?
    Mes principes de bases du codeur qui veut pouvoir dormir:
    • Une variable de moins est une source d'erreur en moins.
    • Un pointeur de moins est une montagne d'erreurs en moins.
    • Un copier-coller, ça doit se justifier... Deux, c'est un de trop.
    • jamais signifie "sauf si j'ai passé trois jours à prouver que je peux".
    • La plus sotte des questions est celle qu'on ne pose pas.
    Pour faire des graphes, essayez yEd.
    le ter nel est le titre porté par un de mes personnages de jeu de rôle

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    91
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 91
    Points : 96
    Points
    96
    Par défaut
    J'ai mis en couleur ce qui ne fonctionne pas

    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_H
    #define MAINWINDOW_H
    
    #include "GlobalesProcedures.h"
    //#include "head.h"         // op2
    //#include "navigants.h"    // op2
    
    #include <QMainWindow>
    #include <QProcess>
    #include <QScreen>
    #include <QDebug>
    #include <QGroupBox>
    #include <QVBoxLayout>
    #include <QTextEdit>
    #include <QLabel>
    #include <QPushButton>
    #include <QTableWidget>
    #include <QFileInfo>
    #include <QHBoxLayout>
    #include <QScrollArea>
    #include <QScrollBar>
    
    
    
    
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    
    public:
        MainWindow(QWidget *parent = nullptr);
        QWidget GeneralTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
        ~MainWindow();
    
    
        struct Personnel{
            QString nom[366];
            QString prenom[366];
            QString fonction[366];
            int joursDus[366];
        } perso;
    
    
        QWidget* widgetPrincipal;
        QWidget* scrollAreaWidgetContentsD;
        QWidget* scrollAreaWidgetContentsG;
        QWidget* scrollAreaWidgetContentsDb;
        QWidget* scrollAreaWidgetContentsGb;
    
        QGridLayout* grilleLayout;
    
        QScrollArea* scrollArea_01;     QWidget* contentWidget_01;
        QScrollArea* scrollArea_10;     QWidget* contentWidget_10;
        QScrollArea* scrollArea_11;     QWidget* contentWidget_11;
    
        QScrollBar* scrollBar_01;
        QScrollBar* scrollBar_10;
        QScrollBar* scrollBar_11_V;
        QScrollBar* scrollBar_11_H;
    
        QVBoxLayout* verticalLayout_01;
        QVBoxLayout* verticalLayout_10;
        QVBoxLayout* verticalLayout_11;
    
    
    public slots:
        void controlerScrollArea_01(int value);
        void controlerScrollArea_10(int value);
    
    
    private:
    
    
    };
    #endif // MAINWINDOW_H
    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
    #include "GlobalesProcedures.h"     //<-- ini
    #include "mainwindow.h"             //<-- ini
    #include "head.h"                   //<-- ini
    #include "navigants.h"              //<-- ini
    
    
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
    
        QProcess::execute("CLS");
    
        this->setWindowTitle("Aide à la création de plannings");
        this->setStyleSheet("QMainWindow {border: 2px solid; border-radius: 5px; Text-align:center;background-color:#000000;}");
        this->setStyleSheet("QMainWindow {color: rgb(00,00,88); background-color:#FFFFFF;}");
    
        this->setWindowState(Qt::WindowMaximized);
        double myScreenW = screen()->geometry().width();
        double myScreenH = screen()->geometry().height()/2;
        this->setMinimumSize(myScreenW, myScreenH);
    
    
    
    
        widgetPrincipal = new QWidget(this);
    
        //QPushButton* b0 = new QPushButton("b0", widgetPrincipal); b0->setFixedSize(40, 900);
        QPushButton* b1 = new QPushButton("b1", widgetPrincipal); b1->setVisible(false);
        //QPushButton* b2 = new QPushButton("b2", widgetPrincipal);
        QPushButton* b3 = new QPushButton("b3", widgetPrincipal);
        //QPushButton* b4 = new QPushButton("b4", widgetPrincipal); b4->setFixedSize(2000, 2000);
        QPushButton* b4 = new QPushButton("b4", widgetPrincipal);
        //QPushButton* b5 = new QPushButton("b5", widgetPrincipal);
        //QPushButton* b6 = new QPushButton("b6", widgetPrincipal);
    
        //
        //          |---------------------|-----------------|---------|
        //          | 0,0                 | 0,1             | 0,2,2,1 |  grilleLayout-->addWidget(widget,ligne,colonne, span, span);
        //          |---------------------|-----------------|         |
        //          | 1,0                 | 1,1             |         |
        //          |                     |                 |         |
        //          |                     |                 |         |
        //          |                     |                 |         |
        //          |---------------------|-----------------|---------|
        //          | 2,0,2,3                                         |
        //          |-------------------------------------------------|
        //
    
        // 1.1 Instantiation des layouts
        grilleLayout = new QGridLayout;
        widgetPrincipal->setLayout(grilleLayout);   // attribue le layout grille au widgetPrincipal
    
    
        scrollArea_01 = new QScrollArea;    contentWidget_01 = new QWidget;     scrollArea_01->setWidget(contentWidget_01);
        scrollArea_10 = new QScrollArea;    contentWidget_10 = new QWidget;     scrollArea_10->setWidget(contentWidget_10);
        scrollArea_11 = new QScrollArea;    contentWidget_11 = new QWidget;     scrollArea_11->setWidget(contentWidget_11);
    
        verticalLayout_01 = new QVBoxLayout;    contentWidget_01->setLayout(verticalLayout_01);
        verticalLayout_10 = new QVBoxLayout;    contentWidget_10->setLayout(verticalLayout_10);
        verticalLayout_11 = new QVBoxLayout;    contentWidget_11->setLayout(verticalLayout_11);
    
    
        grilleLayout->addWidget(b1,0,0);                b1->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum); b1->setFixedWidth(100);
        grilleLayout->addWidget(scrollArea_01,0,1);     scrollArea_01->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Maximum); scrollArea_01->setFixedHeight(85);
        grilleLayout->addWidget(b3,0,2,2,1);            b3->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Minimum);
        grilleLayout->addWidget(scrollArea_10,1,0);     scrollArea_10->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Minimum); scrollArea_10->setFixedWidth(100);
        grilleLayout->addWidget(scrollArea_11,1,1);
        grilleLayout->addWidget(b4,2,0,2,3);
    
        b1->setFixedSize(scrollArea_10->width(), scrollArea_01->height());
        scrollArea_01->setStyleSheet("QScrollArea {border: 2px solid; border-radius: 5px; Text-align:center;background-color:#FFFFFF;}");
        scrollArea_10->setStyleSheet("QScrollArea {border: 2px solid; border-radius: 5px; Text-align:center;background-color:#FFFFFF;}");
        scrollArea_11->setStyleSheet("QScrollArea {border: 2px solid; border-radius: 5px; Text-align:center;background-color:#FFFFFF;}");
    
        scrollBar_01 = new QScrollBar(scrollArea_01);
        scrollBar_10 = new QScrollBar(scrollArea_10);
        scrollBar_11_V = new QScrollBar(scrollArea_11);
        scrollBar_11_H = new QScrollBar(scrollArea_11);
    
        scrollArea_01->setHorizontalScrollBar(scrollBar_01);                   //
        scrollArea_01->setWidgetResizable(true);                               //
        scrollArea_01->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);     //
        scrollArea_01->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);   //
        scrollArea_01->setAlignment(Qt::AlignLeft);                            //
        scrollArea_01->setStyleSheet("QScrollArea {border: 2px solid; border-radius: 5px; Text-align:center;background-color:#FFFFFF;}");
    
        scrollArea_10->setVerticalScrollBar(scrollBar_10);                    //
        scrollArea_10->setWidgetResizable(true);                              //
        scrollArea_10->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);    //
        scrollArea_10->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);  //
        scrollArea_10->setAlignment(Qt::AlignLeft);                           //
        scrollArea_10->setStyleSheet("QScrollArea {border: 2px solid; border-radius: 5px; Text-align:center;background-color:#FFFFFF;}");
    
        scrollArea_11->setVerticalScrollBar(scrollBar_11_V);                  //
        scrollArea_11->setHorizontalScrollBar(scrollBar_11_H);                //
        scrollArea_11->setWidgetResizable(true);                              //
        scrollArea_11->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);     //
        scrollArea_11->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);   //
        scrollArea_11->setAlignment(Qt::AlignLeft);                           //
        scrollArea_11->setStyleSheet("QScrollArea {border: 2px solid; border-radius: 5px; Text-align:center;background-color:#FFFFFF;}");
        connect(scrollBar_11_V, SIGNAL(valueChanged(int)), SLOT(controlerScrollArea_10(int)));
        connect(scrollBar_11_H, SIGNAL(valueChanged(int)), SLOT(controlerScrollArea_01(int)));
    
    
    
        QWidget* entete = new head(contentWidget_01);               // Crée le widget "head",
        verticalLayout_01->addWidget(entete,0 , Qt::AlignTop);      // le place dans le verticalLayout_01
        verticalLayout_01->setSpacing(0);                           // le positionne sans espace
        verticalLayout_01->setContentsMargins(0,1,0,0);             // au plus haut à gauche
        contentWidget_01->setStyleSheet("QWidget {background-color:#CCFFFF;}");
    
        //Personnel p;
        perso.nom[0] = "azerty";
    
        QWidget* personnel = new navigants(contentWidget_10, pstr);       // Crée le widget "personnel",
        verticalLayout_10->addWidget(personnel,0 , Qt::AlignTop);   // le place dans le verticalLayout_10
        verticalLayout_10->setSpacing(0);                           // le positionne sans espace
        verticalLayout_10->setContentsMargins(0,0,0,0);             // au plus haut à gauche
        //contentWidget_10->setStyleSheet("QWidget {background-color:#CCFFFF;}");
    
    
    
        int i = 0;
        do {
            QLabel* lab = new QLabel(QString::number(i), contentWidget_10);
            verticalLayout_10->addWidget(lab);
            QString s = " : -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              -------------              ---------------";
            QLabel* lab2 = new QLabel(QString::number(i)+s, contentWidget_11);
            verticalLayout_11->addWidget(lab2);
            i++;
        } while (i<100);
    
    
    
        setCentralWidget(widgetPrincipal);
    
    }
    
    
    void MainWindow::controlerScrollArea_01(int value) {scrollBar_01->setValue(value);}
    void MainWindow::controlerScrollArea_10(int value) {scrollBar_10->setValue(value);}
    
    
    MainWindow::~MainWindow(){}
    navigants.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
    #ifndef NAVIGANTS_H
    #define NAVIGANTS_H
    
    //#include "GlobalesProcedures.h"   // op2
    #include <QObject>
    #include <QWidget>
    #include <QDebug>
    #include <QPushButton>
    #include <QHBoxLayout>
    
    
    class navigants : public QWidget
    {
        Q_OBJECT
    
    public:
    
    /*
        struct Personnel{
            QString nom[366];
            QString prenom[366];
            QString fonction[366];
            int joursDus[366];
        } perso;
    */
    
        explicit navigants(QWidget *parent = nullptr, int *p=nullptr);
    //    explicit navigants(QWidget *parent = nullptr);
        QList<QPushButton*> list_noms;
    
    
    
    
    signals:
    
    };
    
    #endif // NAVIGANTS_H
    navigants.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
    #include "navigants.h"                  //<-- ini
    #include "GlobalesProcedures.h"         //<-- ini
    
    #include <QFile>
    #include <QRegularExpressionMatch>
    
    
    //navigants::navigants(QWidget *parent)
    navigants::navigants(QWidget *parent, int *p)
        : QWidget{parent}
    {
    
    
    //    qDebug() << per->nom[0];
    
        QString _Personnel = "_Personnel.txt";
        _Personnel = urlParseur("", _Personnel);
    
    
        QFile fichier(_Personnel);
        fichier.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream flux(&fichier);
    
        QString nom[366];  for (int i=0; i<366 ; i++) {nom[i]="";}
        QString prenom[366];   for (int i=0; i<366 ; i++) {prenom[i]="";}
        int fonction[366];       for (int i=0; i<366 ; i++) {fonction[i]=0;}
        int joursDus[366];   for (int i=0; i<366 ; i++) {joursDus[i]=0;}
    
        QString ligne;
        int i=0;
        while(!flux.atEnd())
        {
            ligne = flux.readLine();
            ligne += "-";
            ligne.replace("é","e");     ligne.replace("è","e");     ligne.replace("ê","e");     ligne.replace("ë","e");
            ligne.replace("ô","o");     ligne.replace("ö","o");     ligne.replace("î","i");     ligne.replace("ï","i");
            ligne.replace("à","a");     ligne.replace("â","a");     ligne.replace("ä","a");
    
    
            static const QRegularExpression re("^(\\w+):(\\w+):(\\w+):(\\w+)");     /* expression du type : 27.5133/04/1976 */
            QRegularExpressionMatch match = re.match(ligne);
    
    
            if (match.hasMatch()) {
                nom[i] = match.captured(1);
                prenom[i] = match.captured(2);
                fonction[i] = match.captured(3).toInt();
                joursDus[i] = match.captured(4).toInt();
                qDebug() << match.captured(1) << match.captured(2) << match.captured(3) << match.captured(4);
                i++;
            }
    
    
        }
    
        int nbNavigants = i;
    
    
    
        this->setContentsMargins(0, 0, 0, 0);
    
        QVBoxLayout* MainLayout = new QVBoxLayout();
        this->setLayout(MainLayout);
    
        MainLayout->setSpacing(0);
        MainLayout->setContentsMargins(0,0,0,0);
    
    
    
        i=0;
        do {
            QString s = nom[i]+"\r"+prenom[i];
            QPushButton* nom = new QPushButton(s, this);
            nom->setStyleSheet("QPushButton {border: 1px solid; border-radius: 0px; Text-align:left;background-color:#BBDDCC; font-weight: bold;}");
            list_noms.append(nom);
            MainLayout->addWidget(list_noms[i]);
            i++;
        } while (i<nbNavigants);
    }
    @+

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    91
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 91
    Points : 96
    Points
    96
    Par défaut
    J'ai trouvé, il fallait que je pointe toujours dans la structure Personnel appartenant à MainWindow.
    Il fallait donc que je le disse explicitement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    navigants::navigants(QWidget *parent, MainWindow::Personnel *p)
    Cependant si il y a une meilleur solution qu'une structure je suis preneur.
    un <vecteur> serait plus approprié ? Pourquoi ?
    @+

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

Discussions similaires

  1. Réponses: 22
    Dernier message: 11/05/2014, 17h19
  2. récupérer valeur d'un select et le passer à une autre page
    Par identifiant_bidon dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 21/01/2008, 17h48
  3. Terminer une ligne et en passer une autre (?)
    Par beegees dans le forum Cobol
    Réponses: 6
    Dernier message: 15/01/2008, 09h21
  4. passer à une autre page lors d'un click
    Par Maria1505 dans le forum Servlets/JSP
    Réponses: 3
    Dernier message: 20/08/2007, 23h25
  5. Réponses: 2
    Dernier message: 07/05/2007, 15h47

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