Results 1 to 2 of 2

Thread: QtCharts doesnt show lineseries

  1. #1
    Join Date
    Jun 2018
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default QtCharts doesnt show lineseries

    Hi everyone

    could i have ur attention for a few minutes, please? I´m having a problem to plot a Ricker wavelet . I did an interface where i could choose the arguments for the ricker function, save it on a .ini file and plot the ricker function. I have it running , but it doesn´t show the graph, everything compiles, it runs, the interface dialog shows up, I can select the values, save it to the ini file, but the plot window shows up very quick and disappears, so I put a sleep command at the end of it, with 10s, so I could then see the plot window, but it is blank.
    I did include charts on the .pro file
    I don’t´see anything wrong with the code, why it is not plotting? Some function that is not taking the arguments? Something wrong on my logic? If ricker function and ricker series are inside the interface, when I call the Run_clicked button the arguments should be passed to plot function.
    Any help would be much apreciated.


    here is the code:



    **interface2.h**



    #ifndef INTERFACE2_H
    #define INTERFACE2_H
    #include <QtGui>
    #include <QWidget>
    #include <QtCore/QString>
    #include <QtCore/QFile>
    #include <QtCore/QTextStream>
    #include <QMessageBox>
    #include <cmath>
    #include <QtCharts/QLineSeries>
    #include <QtCharts/QChartView>
    #include <unistd.h>

    using namespace QtCharts;

    namespace Ui {
    class interface2;
    }


    class interface2 : public QWidget
    {
    Q_OBJECT

    public:
    explicit interface2(QWidget *parent = 0);
    ~interface2();

    QVector<QPointF> ricker(double f, double dt ,double length);
    QLineSeries* rickerSeries(double f);

    double length;
    int number_traces;
    int trace_samples;
    double sampling_rate;
    int polarity;
    double wavelet_freq;
    bool noise;
    bool standard_reflec;
    double f;
    double dt1;
    double dt;
    const double pi = 3.14159265358979323846;

    private:
    Ui::interface2 *ui;
    void plot();


    private slots:
    void on_RUN_clicked();

    };

    #endif // INTERFACE2_H

    **interface2.cpp**

    #include "interface2.h"

    #include "ui_interface2.h"





    const double pi = 3.14159265358979323846;





    QVector<QPointF> interface2::ricker(double f, double dt ,double length)

    {

    size_t N = (length - dt/2.0)/dt;

    QVector<QPointF> w(N);

    for (size_t i = 0; i < N; ++i)

    {

    double t = -length/2 + i*dt;

    w[i].setX(t);

    w[i].setY(polarity*((1.0 - 2*pi*pi*f*f*t*t) * exp(-pi*pi*f*f*t*t)));

    }

    return w;

    }





    QLineSeries* interface2::rickerSeries(double f) {

    auto *series = new QLineSeries;

    series->setName(QStringLiteral("Ricker Wavelet for f=%1").arg(f, 2));

    series->replace(interface2::ricker(f, dt, length));

    return series;



    }



    void interface2:lot()

    {

    QChartView view;

    view.chart()->addSeries(rickerSeries(f));

    view.chart()->createDefaultAxes();

    view.setMinimumSize(800, 600);

    view.show();

    sleep(10);



    }

    interface2::interface2(QWidget *parent) :

    QWidget(parent),

    ui(new Ui::interface2)



    {



    ui->setupUi(this);



    }





    interface2::~interface2()

    {

    delete ui;

    }





    void interface2:n_RUN_clicked()

    {



    length=ui->length->value();

    number_traces = ui->traces->value();

    trace_samples = ui->samples->value();

    sampling_rate = ui->rate->value();

    dt1=ui->rate->value();

    wavelet_freq = ui->freq->value();

    f=ui->freq->value();

    dt=dt1/1000;



    {

    if(ui->reflectivity->isChecked())/*refletividade padrao*/

    {

    standard_reflec= 1;

    }

    else

    {

    standard_reflec= 0;

    }

    }





    {

    if(ui->Noise->isChecked())/*introduzir ruido*/

    {

    noise= 1;

    }

    else

    {

    noise= 0;

    }

    }



    {

    if(ui->negative->isChecked())/*polaridade negativa*/

    {

    polarity=-1;

    }



    }



    {

    if(ui->positive->isChecked())/*polaridade positiva*/

    {

    polarity=1;

    }

    }





    {



    QString outputFilename = "sismica1.ini";

    QFile outputFile(outputFilename);

    outputFile.open(QIODevice::WriteOnly|QIODevice::Te xt);



    /* Check it opened OK */

    if(!outputFile.isOpen())

    {

    QMessageBox::warning(this,tr("Sismica"),tr("- Error, unable to open sismica1.ini for output"));



    }



    /* Point a QTextStream object at the file */

    QTextStream outStream(&outputFile);



    /* Write the line to the file */

    outStream << "////////////////////////////////////////////////////////////////////////////////////"<<endl

    << "// INITIALIZATION FILE FOR SISMICA1 PROGRAM //"<<endl


    << "Impedancia.txt"<<"\n"

    << number_traces<<"\n"

    << trace_samples<<"\n"

    << sampling_rate/1000<<"\n"

    << wavelet_freq<<"\n"

    << polarity<<"\n"

    << noise<<"\n"

    << standard_reflec<<"\n";



    /* Close the file */

    outputFile.close();



    }

    plot();

    }

    **main.cpp**

    #include "interface2.h"

    #include "ui_interface2.h"

    #include <QApplication>





    int main(int argc, char *argv[])

    {



    QApplication a(argc, argv);

    interface2 w;

    w.show();



    return a.exec();



    }

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,766
    Thanks
    216
    Thanked 582 Times in 572 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QtCharts doesnt show lineseries

    Please use CODE tags when posting source code. Geez. How many times do people have to say that?

    Qt Code:
    1. void interface2:lot()
    2. {
    3. QChartView view;
    4.  
    5. view.chart()->addSeries(rickerSeries(f));
    6.  
    7. view.chart()->createDefaultAxes();
    8.  
    9. view.setMinimumSize(800, 600);
    10.  
    11. view.show();
    12.  
    13. sleep(10);
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    Do you understand object lifetimes in C++? What do you think happens to the local QChartView instance you have created on the stack when this slot exits? As for the series not being displayed, the chart will not update itself until the Qt event loop has a chance to run, and that won't happen until the slot exits. And when the slot exits, what happens to the QChartView instance?

    It seems to me that you need to take a few steps back and study some of the Qt examples (and C++) until you understand what event-driven programming is all about. You can't take a functional logic C or C++ program and simply convert the functional logic flow and expect it to work the same way in an event-driven framework. In an event-driven program, your code is not in charge of the flow of execution. The Qt event loop is, and it will call functions in your code that are tied to user interface or system events, not the other way around.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. qwt vs qtcharts
    By hassinoss in forum Qwt
    Replies: 1
    Last Post: 13th January 2017, 06:50
  2. QtChart LineSeries SplineSeries question
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 18th October 2016, 19:48
  3. widget doesnt show
    By tuli in forum Qt Programming
    Replies: 4
    Last Post: 5th September 2012, 11:23
  4. QWT doesnt show any windows
    By Cal in forum Qwt
    Replies: 5
    Last Post: 30th June 2009, 17:05
  5. showMaximized doesnt show the canvas
    By Kapil in forum Qt Programming
    Replies: 5
    Last Post: 23rd May 2006, 12:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.