Salut,
dans le cadre d'un TP, j'ai créer deux fenêtres créer par deux classes.
Mon travail consiste à générer un diagramme à partir d'une valeur tapait par l'utilisateur (après passage par une fonction pour lui appliqué une loi), donc j'ai pris les tuto de la SFML : http://www.sfml-dev.org/tutorials/1....hics-qt-fr.php , et j'ai ajouter une simple classe :

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
class MaFenetre : public QWidget
{
    Q_OBJECT
 
    public:
    MaFenetre();
 
    public:
    QFrame *frame;
 
    public:
    QVBoxLayout *layoutPrincipal;
 
    public:
    QVBoxLayout *layoutBouton;
 
    public:
    QFormLayout *formulaire;
 
    public:
    QLineEdit *premiere_valeur;
 
    public:
    QPushButton *bouton_valider;
 
    public slots:
    void valider();
 
};
Mon problème c'est que mon graphe s'affiche juste la première et après il ne se plus à jour.

je pense que c'est pas claire, je vais mettre tout le code :


QSFMLCanvas.hpp:

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
#ifndef QSFMLCANVAS_HPP
#define QSFMLCANVAS_HPP
 
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <Qt/qwidget.h>
#include <Qt/qtimer.h>
 
#include <QApplication>
#include <QtGui>
 
class MaFenetre : public QWidget
{
    Q_OBJECT
 
    public:
    MaFenetre();
 
    public:
    QFrame *frame;
 
    public:
    QFrame *frame2;
 
    public:
    QFrame *frame3;
 
    public:
    QVBoxLayout *layoutPrincipal;
 
    public:
    QVBoxLayout *layoutPrincipal2;
 
    public:
    QVBoxLayout *layoutPrincipal3;
 
    public:
    QVBoxLayout *layoutBouton;
 
    public:
    QFormLayout *formulaire;
 
    public:
    QFormLayout *formulaire2;
 
    public:
    QLineEdit *premiere_valeur;
    QLineEdit *deuxieme_valeur;
    QLineEdit *troisieme_valeur;
 
    public:
    QComboBox *liste;
 
    public:
    QPushButton *bouton_valider;
 
    public:
    double x,y;
 
    public slots:
    void valider();
 
};
 
 
////////////////////////////////////////////////////////////
/// QSFMLCanvas allows to run SFML in a Qt control
////////////////////////////////////////////////////////////
class QSFMLCanvas : public QWidget, public sf::RenderWindow
{
public :
 
    ////////////////////////////////////////////////////////////
    /// Construct the QSFMLCanvas
    ///
    /// \param Parent :    Parent of the widget
    /// \param Position :  Position of the widget
    /// \param Size :      Size of the widget
    /// \param FrameTime : Frame duration, in milliseconds (0 by default)
    ///
    ////////////////////////////////////////////////////////////
    QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime = 0);
 
    ////////////////////////////////////////////////////////////
    /// Destructor
    ///
    ////////////////////////////////////////////////////////////
    virtual ~QSFMLCanvas();
 
private :
 
    ////////////////////////////////////////////////////////////
    /// Notification for the derived class that moment is good
    /// for doing initializations
    ///
    ////////////////////////////////////////////////////////////
    virtual void OnInit();
 
    ////////////////////////////////////////////////////////////
    /// Notification for the derived class that moment is good
    /// for doing its update and drawing stuff
    ///
    ////////////////////////////////////////////////////////////
    virtual void OnUpdate();
 
    ////////////////////////////////////////////////////////////
    /// Called when the widget is shown ;
    /// we use it to initialize our SFML window
    ///
    ////////////////////////////////////////////////////////////
    virtual void showEvent(QShowEvent*);
 
    ////////////////////////////////////////////////////////////
    /// Called when the widget needs to be painted ;
    /// we use it to display a new frame
    ///
    ////////////////////////////////////////////////////////////
    virtual void paintEvent(QPaintEvent*);
 
    ////////////////////////////////////////////////////////////
    // Member data
    ////////////////////////////////////////////////////////////
    QTimer myTimer;       ///< Timer used to update the view
    bool   myInitialized; ///< Tell whether the SFML window has been initialized or not
};
 
 
#endif // QSFMLCANVAS_HPP

QSFMLCanvas.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
 
 
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "QSFMLCanvas.hpp"
 
// Platform-specific headers
#ifdef Q_WS_X11
    #include <Qt/qx11info_x11.h>
    #include <X11/Xlib.h>
#endif
 
MaFenetre::MaFenetre() : QWidget()
{
    setFixedSize(600, 300);//donner une taille à la fenetre
 
    frame = new QFrame(this);
    frame->setFrameShape(QFrame::StyledPanel);
    frame->setGeometry(10, 10, 580, 130);
 
    frame2 = new QFrame(this);
    frame2->setFrameShape(QFrame::StyledPanel);
    frame2->setGeometry(10, 160, 580, 100);
 
 
    premiere_valeur = new QLineEdit;
    premiere_valeur->setFixedSize(100,20);
    deuxieme_valeur = new QLineEdit;
    deuxieme_valeur->setFixedSize(100,20);
    troisieme_valeur = new QLineEdit;
    troisieme_valeur->setFixedSize(100,20);
    troisieme_valeur->setText("avant");
    liste = new QComboBox;
    liste->setFixedSize(100,20);
    liste->addItem("Binominale");
    liste->addItem("de Poisson");
 
 
    formulaire = new QFormLayout;
    formulaire2 = new QFormLayout;
 
 
    // Création du layout principal de la fenêtre (vertical)
    layoutPrincipal = new QVBoxLayout;
    layoutPrincipal2 = new QVBoxLayout;
 
 
    formulaire->addRow("1ere Valeur", premiere_valeur);
    formulaire->addRow("2eme Valeur", deuxieme_valeur);
    formulaire->addRow("Fonction", liste);
    formulaire2->addRow("Essai :", troisieme_valeur);
 
 
    layoutPrincipal->addLayout(formulaire);//Ajout du layout de formulaire au Layoutpricipal
    layoutPrincipal2->addLayout(formulaire2);//Ajout du layout de formulaire au Layoutpricipal
 
    //layoutBouton = new QVBoxLayout;//layout pour le bouton
    bouton_valider = new QPushButton("Valider",this);
    //bouton_valider->setGeometry(120, 60, 160, 80);
    bouton_valider->move(300,100);
 
 
    QWidget::connect(bouton_valider, SIGNAL(clicked()), this, SLOT(valider()));
 
 
    frame->setLayout(layoutPrincipal);
    frame2->setLayout(layoutPrincipal2);
 
 
}
 
void MaFenetre::valider()
{
     //QString x = premiere_valeur->text();
     x = premiere_valeur->text().toDouble();//lecture de la 1ere donnée
     y = deuxieme_valeur->text().toDouble();//lecture de la 2eme donnée
     QString fonction = liste->currentText();
 
     troisieme_valeur->setText(fonction);
     //troisieme_valeur->setText(fonction);
}
 
 
 
 
////////////////////////////////////////////////////////////
/// Construct the QSFMLCanvas
////////////////////////////////////////////////////////////
QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) :
QWidget       (Parent),
myInitialized (false)
{
    // Setup some states to allow direct rendering into the widget
    setAttribute(Qt::WA_PaintOnScreen);
    setAttribute(Qt::WA_NoSystemBackground);
 
    // Setup the widget geometry
    move(Position);
    resize(Size);
 
    // Setup the timer
    myTimer.setInterval(FrameTime);
}
 
 
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
QSFMLCanvas::~QSFMLCanvas()
{
    // Nothing to do...
}
 
 
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing initializations
////////////////////////////////////////////////////////////
void QSFMLCanvas::OnInit()
{
    // Nothing to do by default...
}
 
 
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing its update and drawing stuff
////////////////////////////////////////////////////////////
void QSFMLCanvas::OnUpdate()
{
    // Nothing to do by default...
}
 
 
////////////////////////////////////////////////////////////
/// Called when the widget is shown ;
/// we use it to initialize our SFML window
////////////////////////////////////////////////////////////
void QSFMLCanvas::showEvent(QShowEvent*)
{
    if (!myInitialized)
    {
        // Create the SFML window with the widget handle
        Create(winId());
 
        // Let the derived class do its specific stuff
        OnInit();
 
        // Setup the timer to trigger a refresh at specified framerate
        connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
        myTimer.start();
 
        myInitialized = true;
    }
}
 
 
////////////////////////////////////////////////////////////
/// Called when the widget needs to be painted ;
/// we use it to display a new frame
////////////////////////////////////////////////////////////
void QSFMLCanvas::paintEvent(QPaintEvent*)
{
    // Let the derived class do its specific stuff
    OnUpdate();
 
    // Display on screen
    Display();
}

graphics-qt.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
 
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "QSFMLCanvas.hpp"
#include <Qt/qapplication.h>
#include <Qt/qframe.h>
 
////////////////////////////////////////////////////////////
/// Custom SFML canvas
////////////////////////////////////////////////////////////
class MyCanvas : public QSFMLCanvas
{
public :
 
    ////////////////////////////////////////////////////////////
    /// Construct the canvas
    ///
    ////////////////////////////////////////////////////////////
    MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size) :
    QSFMLCanvas(Parent, Position, Size)
    {
 
    }
 
private :
 
    ////////////////////////////////////////////////////////////
    /// /see QSFMLCanvas::OnInit
    ///
    ////////////////////////////////////////////////////////////
    void OnInit()
    {
        // Change the background color
        SetBackgroundColor(sf::Color(0, 255, 0));
    }
 
    ////////////////////////////////////////////////////////////
    /// /see QSFMLCanvas::OnUpdate
    ///
    ////////////////////////////////////////////////////////////
    void OnUpdate()
    {
        Draw(sf::Shape::Line(10, 290, 290, 290, 10, sf::Color::Red));//Axe des X
        Draw(sf::Shape::Line(10, 10, 10, 295, 10, sf::Color::Red));//Axe des Y
 
        double x1 = MaFenetre().x;
        Draw(sf::Shape::Line(10, 10, x1, x1, 10, sf::Color::Blue));
    }
 
    ////////////////////////////////////////////////////////////
    /// Member data
    ////////////////////////////////////////////////////////////
    sf::Image  myImage;  ///< Some image to show
    sf::Sprite mySprite; ///< A sprite to display the image
};
 
 
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
    QApplication App(argc, argv);
 
    MaFenetre fenetre;
    fenetre.show();
 
    // Create the main frame
    QFrame* MainFrame = new QFrame;
    MainFrame->setWindowTitle("Qt SFML");
    MainFrame->resize(350, 350);
    MainFrame->show();
 
 
    // Create a SFML view inside the main frame
    MyCanvas* SFMLView = new MyCanvas(MainFrame, QPoint(20, 20), QSize(300, 300));
      SFMLView->show();
 
    return App.exec();
}

A noter que j'ai juste ajouter quelque ligne dans la fonction OnUpdate()


Merci de bien vouloir m'aider.