Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qwt plot inside QDialog inside QWidget?



  • Hi

    I do my first steps with qwt and I already stumbled upon a simple task.
    I have a MainWindow (QWidget) that contains a QPushButton which will
    open a PlotWindow (QDialog) that SHALL be filled by a Qwt Plot.
    I used a QDialog because I want the PlotWindow close if I close the MainWindow.
    The Qwt plot shall use all the space available in the PlotWindow

    // mainwindow.h
    
    #include <QWidget>
    #include <QPushButton>
    #include "plotwindow.h"
    class MainWindow : public QWidget
    {
        Q_OBJECT
    public:
        explicit MainWindow(QWidget *parent=nullptr);
    private:
        QPushButton *pushbutton;
        PlotWindow *plotWindow;
    private slots:
        void showPlotWindow();
    };
    
    // mainwindow.cpp
    
    #include "mainwindow.h"
    MainWindow::MainWindow(QWidget *parent)
        :QWidget(parent)
    {
        pushbutton = new QPushButton("PLOT",this);
        plotWindow = new PlotWindow(this);
        connect(pushbutton,&QPushButton::clicked,this,&MainWindow::showPlotWindow);
    }
    
    void MainWindow::showPlotWindow()
    {
        plotWindow->show();
    }
    
    // plotwindow.h
    
    #include <QDialog>
    #include <qwt/qwt_plot.h>
    
    
    class PlotWindow : public QDialog
    {
        Q_OBJECT
    public:
        explicit PlotWindow(QWidget *parent=nullptr);
    private:
    
    };
    
    // plotwindow.cpp
    
    #include "plotwindow.h"
    #include <qwt/qwt_text.h>
    PlotWindow::PlotWindow(QWidget *parent)
        :QDialog(parent)
    {
        QwtPlot *plot = new QwtPlot( "Test", parent );
        resize(233,222);
    }
    

    If I compile the code I get this error:

    /home/p/store/c++/qt/qwt_test/plotwindow.cpp:6: error: no matching function for call to ‘QwtPlot::QwtPlot(const char [5], QWidget*&)’
        6 |     QwtPlot *plot = new QwtPlot( "Test", parent );
          |                                                 ^
    

    Whats wrong here?



  • ok, stupid me! I forgot to include Qwt in the *.pro file:

    ...
    CONFIG += qwt
    INCLUDEPATH +="/usr/include/qwt"
    LIBS += -L/usr/lib -lqwt