Bonjour,

J'ai un petit problème avec un QScrollArea.
Sur le côté de mon application, j'ai un QTreeView où tous les fichiers audio qu'a ouvert l'utilisateur sont listés. Lorsqu'il click sur un nom de fichier je charge le graph (un qwtplot) correspondant dans le QScrollArea. Les graphs sont créés quand l'utilisateur ouvre les fichiers et sont stockés dans une liste (graphs). Jusque là tout va bien.
Par contre, quand l'utilisateur reclick sur un nom de fichier qui a déjà été affiché, mon programme plante.

Je sais pas si c'était bien clair.

Voici mes codes:
Méthode pour changer le graph (les left et right sliders sont pour créer des qwtplotmarker sur le graph)
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::changeGraph(int index){
 
    int max=graphs[index].getMaxLegend();
    ui->scrollArea->setWidget(graphs[index].getWaveForm());
 
    ui->leftSlider->setMaximum(max);
    ui->leftSlider->setValue(0);
    ui->leftSlider->setToolTip("0");
    ui->rightSlider->setMaximum(max);
    ui->rightSlider->setValue(graphs[index].getFrames());
    ui->rightSlider->setToolTip(QString::number(graphs[index].getFrames()));
}
Le constructeur de graph (waveform est le qwtplot que je mets en champs privée pour pouvoir le récupérer et le mettre dans le scrollarea)
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
 
Graph::Graph( const string & path )
{
    SF_INFO fileInfos;
    SNDFILE* audFile = sf_open(path.c_str(), SFM_READ, &fileInfos);
 
    // stock point to draw
    QVector<QPointF> v;
 
    // stock current frame
    double currentFrame[2];
 
    // go to start of data
    sf_seek(audFile,0,SEEK_SET);
 
    // readings frames
    for (sf_count_t i=0;i<fileInfos.frames;i++){
        // reading frame i
        sf_read_double(audFile,currentFrame,fileInfos.channels);
 
        // stock frame points
        v.append(QPointF(i,currentFrame[0]));
        v.append(QPointF(i, fileInfos.channels == 1?0:currentFrame[1]));
    }
 
    // create plot
    string fileName=path.substr(path.find_last_of("/\\")+1);
    QwtPlot* mp = new QwtPlot( QwtText("WaveForm - "+ QString::fromStdString(fileName)));
    mp->setWindowTitle( mp->title().text() );
 
    // create curve
    QwtPlotCurve* c = new QwtPlotCurve(QString::fromStdString(fileName));
 
    // set curve datas
    c->setSamples(QPolygonF(v));
 
    // attache curve to plot
    c->attach(mp);
 
    //create the markers
    leftMarker = new QwtPlotMarker();
    leftMarker->setLineStyle(QwtPlotMarker::VLine);
    leftMarker->setLinePen(QPen(Qt::red));
    leftMarker->setLabel(QString::fromUtf8("Beginning"));
    leftMarker->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    leftMarker->setXValue(0);
    rightMarker = new QwtPlotMarker();
    rightMarker->setLineStyle(QwtPlotMarker::VLine);
    rightMarker->setLinePen(QPen(Qt::red));
    rightMarker->setLabel(QString::fromUtf8("End"));
    rightMarker->setLabelAlignment(Qt::AlignLeft|Qt::AlignTop);
    rightMarker->setXValue(fileInfos.frames);
    leftMarker->attach(mp);
    rightMarker->attach(mp);
 
    // replot
    mp->replot();
 
    // return plot
    waveForm= mp;
    frames=fileInfos.frames;
    sf_close(audFile);
}
J'imagine que je fais un micmac avec les pointeurs, mais je ne vois pas où.

Merci d'avance
Olivier