invalid use of incomplete type ‘class Ui::Task’ Qt with C++
Unsolved
General and Desktop
-
Hi friends,
I am learning with the book called Mastering Qt5.
I don't understand why the following error appears:
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.
-
@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" -
It's the same thing as last time.