Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Class declaration error
Qt 6.11 is out! See what's new in the release blog

Class declaration error

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 9.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aurora
    wrote on last edited by
    #1

    I'm writting a code, where i'm using designer to design the form and i also needed to update that form dynamically....
    when i not used designer to design the form, my code was like this...

    mainwindow.h

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QtGui/QMainWindow>
     
    class QVBoxLayout;
     
    class MainWindow : public QMainWindow
    {
    Q_OBJECT
     
    public slots:
    void addRow( void );
     
    public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
     
    private:
    QVBoxLayout* m_layout;
    };
     
    #endif // MAINWINDOW_H@
    

    mainwindow.cpp
    @
    #include "mainwindow.h"

    #include <QVBoxLayout>
    #include <QHBoxLayout>
    #include <QPushButton>
    #include <QLineEdit>
     
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent),
    m_layout( new QVBoxLayout() )
    {
    QPushButton* add = new QPushButton("Add");
    connect(add, SIGNAL(clicked()), this, SLOT(addRow()));
     
    m_layout->addWidget(add);
    m_layout->setAlignment(Qt::AlignTop);
     
    QWidget* w = new QWidget();
    w->setLayout(m_layout);
     
    this->setCentralWidget(w);
    }
     
    MainWindow::~MainWindow()
    {
     
    }
     
    void MainWindow::addRow( void )
    {
    QLineEdit* line = new QLineEdit();
    QPushButton* clear = new QPushButton("Clear");
    QPushButton* remove = new QPushButton("Remove");
     
    QHBoxLayout* layout = new QHBoxLayout();
    layout->setMargin(0);
    layout->addWidget(line);
    layout->addWidget(clear);
    layout->addWidget(remove);
     
    QWidget* w = new QWidget();
    w->setLayout(layout);
     
    connect(clear, SIGNAL(clicked()), line, SLOT(clear()));
    connect(remove, SIGNAL(clicked()), w, SLOT(deleteLater()));
     
    m_layout->addWidget(w);
    }@
    

    but inorder to include my form which is designed using Qt designer...i changed it as follows..
    MainWindow::MainWindow(QWidget parent)
    @ : QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_layout( new QVBoxLayout() )
    {
    ui->setupUi(this);
    QPushButton
    add = new QPushButton("Add");
    connect(add, SIGNAL(clicked()), this, SLOT(addRow()));

    m_layout->addWidget(add);
    .............
    .............@
    

    But here i'm getting error saying..
    error: class 'MainWindow' does not have any field named 'ui'
    error: invalid use of incomplete type 'struct Ui::MainWindow'
    error: forward declaration of 'struct Ui::MainWindow'
    error: 'ui' was not declared in this scope

    please help me wher i'm going wrong..!!!?

    Moderator note: please don't shout. Using all caps and three exclamation marks is considered shouting, and thus rude. Also, the Qt Quick forum is not for quick answers, but about the QML/Quick technology, so I moved your topic. Andre

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rokemoon
      wrote on last edited by
      #2

      Here is the default defenition of MainWindow with form.
      Header:
      @

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H

      #include <QMainWindow>

      namespace Ui {
      class MainWindow;
      }

      class MainWindow : public QMainWindow
      {
      Q_OBJECT

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

      private:
      Ui::MainWindow *ui;
      };

      #endif // MAINWINDOW_H
      @
      Source:
      @

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

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

      MainWindow::~MainWindow()
      {
      delete ui;
      }
      @
      So look what you miss and try to correct.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aurora
        wrote on last edited by
        #3

        i did,,,,but i'm getting error saying that
        error: invalid use of incomplete type 'struct Ui::MainWindow'

        at line... " ui(new Ui::MainWindow)" in the code
        @MainWindow::MainWindow(QWidget parent)
        : QMainWindow(parent),
        ui(new Ui::MainWindow),
        m_layout( new QVBoxLayout() )
        {
        ui->setupUi(this);
        QPushButton
        add = new QPushButton("Add");
        connect(add, SIGNAL(clicked()), this, SLOT(addRow()));@

        please let me know whats wrong?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rokemoon
          wrote on last edited by
          #4

          Have you add this @#include "ui_mainwindow.h"@ ?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Having an "undefined <something>" error almost always is the result of one of these errors:

            • A typo in the type name
            • A forgotten #include

            There are some other possibilities, but I won't bore you with those.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved