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. invalid use of incomplete type ‘class Ui::Task’ Qt with C++
Forum Update on Monday, May 27th 2025

invalid use of incomplete type ‘class Ui::Task’ Qt with C++

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 291 Views
  • 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.
  • G Offline
    G Offline
    grafenocarbono
    wrote on 9 Mar 2024, 12:46 last edited by
    #1

    Hi friends,

    I am learning with the book called Mastering Qt5.

    I don't understand why the following error appears:

    error code

    My class Task.h is the following:

    #ifndef TASK_H
    #define TASK_H
    
    #include <QWidget>
    #include <QString>
    
    namespace Ui {
    class Task;
    }
    
    class Task : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit Task(const QString& name, QWidget *parent = 0);
        ~Task();
    
        void setName(const QString& name);
        QString name() const;
        bool isCompleted() const;
    
    public slots:
        void rename();
    
    signals:
        void removed(Task* task);
        void statusChanged(Task* task);
    
    private slots:
        void checked(bool checked);
    
    private:
        Ui::Task *ui;
    };
    
    #endif // TASK_H
    
    
    

    My class Task.cpp is the following:

    #include "Task.h"
    
    #include <QInputDialog>
    #include <QDebug>
    
    Task::Task(const QString& name, QWidget *parent) :
        QWidget(parent),
        ui(new Task)
    {
        ui->setupUi(this);
        setName(name);
    
        connect(ui->editButton, &QPushButton::clicked, this, &Task::rename);
        connect(ui->removeButton, &QPushButton::clicked, [this] {
            emit removed(this);
        });
        connect(ui->checkbox, &QCheckBox::toggled, this, &Task::checked);
    }
    
    Task::~Task()
    {
        qDebug() << "~Task() called";
        delete ui;
    }
    
    void Task::setName(const QString& name)
    {
        ui->checkbox->setText(name);
    }
    
    QString Task::name() const
    {
        return ui->checkbox->text();
    }
    
    bool Task::isCompleted() const
    {
        return ui->checkbox->isChecked();
    }
    
    void Task::rename()
    {
        bool ok;
        QString value = QInputDialog::getText(this, tr("Edit task"),
                                              tr("Task name"), QLineEdit::Normal,
                                              this->name(), &ok);
        if (ok && !value.isEmpty()) {
            setName(value);
        }
    }
    
    void Task::checked(bool checked)
    {
        QFont font(ui->checkbox->font());
        font.setStrikeOut(checked);
        ui->checkbox->setFont(font);
    
        emit statusChanged(this);
    }
    
    
    

    Thanks in Advance.

    M 1 Reply Last reply 9 Mar 2024, 13:40
    0
    • G grafenocarbono
      9 Mar 2024, 12:46

      Hi friends,

      I am learning with the book called Mastering Qt5.

      I don't understand why the following error appears:

      error code

      My class Task.h is the following:

      #ifndef TASK_H
      #define TASK_H
      
      #include <QWidget>
      #include <QString>
      
      namespace Ui {
      class Task;
      }
      
      class Task : public QWidget
      {
          Q_OBJECT
      
      public:
          explicit Task(const QString& name, QWidget *parent = 0);
          ~Task();
      
          void setName(const QString& name);
          QString name() const;
          bool isCompleted() const;
      
      public slots:
          void rename();
      
      signals:
          void removed(Task* task);
          void statusChanged(Task* task);
      
      private slots:
          void checked(bool checked);
      
      private:
          Ui::Task *ui;
      };
      
      #endif // TASK_H
      
      
      

      My class Task.cpp is the following:

      #include "Task.h"
      
      #include <QInputDialog>
      #include <QDebug>
      
      Task::Task(const QString& name, QWidget *parent) :
          QWidget(parent),
          ui(new Task)
      {
          ui->setupUi(this);
          setName(name);
      
          connect(ui->editButton, &QPushButton::clicked, this, &Task::rename);
          connect(ui->removeButton, &QPushButton::clicked, [this] {
              emit removed(this);
          });
          connect(ui->checkbox, &QCheckBox::toggled, this, &Task::checked);
      }
      
      Task::~Task()
      {
          qDebug() << "~Task() called";
          delete ui;
      }
      
      void Task::setName(const QString& name)
      {
          ui->checkbox->setText(name);
      }
      
      QString Task::name() const
      {
          return ui->checkbox->text();
      }
      
      bool Task::isCompleted() const
      {
          return ui->checkbox->isChecked();
      }
      
      void Task::rename()
      {
          bool ok;
          QString value = QInputDialog::getText(this, tr("Edit task"),
                                                tr("Task name"), QLineEdit::Normal,
                                                this->name(), &ok);
          if (ok && !value.isEmpty()) {
              setName(value);
          }
      }
      
      void Task::checked(bool checked)
      {
          QFont font(ui->checkbox->font());
          font.setStrikeOut(checked);
          ui->checkbox->setFont(font);
      
          emit statusChanged(this);
      }
      
      
      

      Thanks in Advance.

      M Offline
      M Offline
      mpergand
      wrote on 9 Mar 2024, 13:40 last edited by mpergand 3 Sept 2024, 13:41
      #2

      @grafenocarbono
      Hi,

      It seems the ui definition file is missing, in your cpp file, it should have been included, maybe somthing like that:
      #include "ui_task.h"

      1 Reply Last reply
      3
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 9 Mar 2024, 14:51 last edited by
        #3

        It's the same thing as last time.

        1 Reply Last reply
        4

        1/3

        9 Mar 2024, 12:46

        • Login

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