Using Qt Creator (with Qwt), really basic stuff

I am trying to make a Qt program using Qt Creator and Qwt to plot. I have never used Qt Creator before. I created MainWindow and added a Qwtplot widget there (object name: qwtPlot). The widget appears in the program when I compile and run it. But the qwtPlot object is not mentioned anywhere in the (auto-generated) code, so I assume that it is added at compile time from the .ui xml file (or something else).

My question is ... how do I change / change the qwtPlot object? Or where should I put the code?

It is difficult for me to formulate my question, but basically the question: "How can I do something with the qwtPlot widget, which is created (graphically) using Qtcreator?". I checked a few tutorials, but in the tutorials they added widgets manually in the code, but I would like to use Qt Creator (because my user interface will be quite complicated). This whole Qt Creator is pretty confusing ...

+3
source share
1 answer

A typical solution is to use multiple inheritance or to include a user interface component as a private member. Qt explains the process on its website:

Using the designer user interface file in the application

( , ... 2.0.1)

( ) mainwindow.h, Ui::MainWindow.

class MainWindow : public QMainWindow
{
  Q_OBJECT

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

private:
  Ui::MainWindow *ui;
};

mainwindow.cpp , ui.

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow) {
    ui->setupUi(this);
    ui->myControl->setProperty(...);
}

MainWindow::~MainWindow() {
    delete ui;
}

, .

+4

Source: https://habr.com/ru/post/1783890/


All Articles