M
M
Maxim Rudnev2016-10-04 16:03:16
Qt
Maxim Rudnev, 2016-10-04 16:03:16

How to access ui qT elements?

Such a problem:
I create a QT project in the studio, I add a GUI class. In the designer I make one button pushButton
.hpp

#pragma once
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <QMainWindow>
namespace Ui {class MainWindow;}

class MainWindow : public QMainWindow {
  Q_OBJECT

public:
  MainWindow(QWidget * parent = Q_NULLPTR);
  ~MainWindow();
  
public:
  Ui::MainWindow *ui;
};

#endif // MAINWINDOW_HPP

.cpp
#include "mainwindow.hpp"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) {
  ui = new Ui::MainWindow();
  ui->setupUi(this); 
  

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

The whole drama lies in the lack of ui elements in mainwindow.cpp.
When I start typing ui-> I get only a list instead of elements: setupUi
I can't do anything with pushButton in mainwindow.cpp.
But! When I create an empty project directly in QtCreator and add a button to the form, I get access to everything I need using the ui-> method.
Why is it different in studio with qt addon? why can't I access the button on the form from the studio code editor? why does the same in QT work ok?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2016-10-04
@electronik777

try to build the project after adding the elements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question