I followed the instruction on the Qt website step by step to create my first widget based application.
In the main file I have
#include "textfinder.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TextFinder w;
w.show();
return a.exec();
}
In the Header file:
#ifndef TEXTFINDER_H
#define TEXTFINDER_H
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui { class TextFinder; }
QT_END_NAMESPACE
class TextFinder : public QWidget
{
Q_OBJECT
public:
TextFinder(QWidget *parent = nullptr);
~TextFinder();
private slots:
void on_pushButton_clicked();
private:
Ui::TextFinder *ui;
void loadTextFile();
};
#endif // TEXTFINDER_H
and in the source file I have
#include "textfinder.h"
#include "./ui_textfinder.h"
#include <QFile>
#include <QTextStream>
TextFinder::TextFinder(QWidget *parent)
: QWidget(parent)
, ui(new Ui::TextFinder)
{
ui->setupUi(this);
loadTextFile();
}
TextFinder::~TextFinder()
{
delete ui;
}
void TextFinder::on_pushButton_clicked()
{
QString searchString = ui->lineEdit->text();
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
}
void TextFinder::loadTextFile()
{
QFile inputFile(":/input.txt");
inputFile.open(QIODevice::ReadOnly);
QTextStream in(&inputFile);
QString line = in.readAll();
inputFile.close();
ui->textEdit->setPlainText(line);
QTextCursor cursor = ui->textEdit->textCursor();
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
}
In the ``textfinder.ui``` file I have the following

The projects sources in the CMakeLists.txt file are
set(PROJECT_SOURCES
main.cpp
textfinder.cpp
textfinder.h
textfinder.ui
${TS_FILES}
textfinder.qrc
)
If I press run now I get the error message invalid use of incomplete type 'class Ui::TextFinder'. But I thought I do not have to care for the ui_textfinder.h file since this will be autogenerated. By reading the other questions/answers I think it could have to do with the naming. But I can not understand where my mistake is since I followed the tutorial carefully.
EDIT-------- The missing ui_textfinder.h file -------
#ifndef UI_TEXTFINDER_H
#define UI_TEXTFINDER_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_findButton
{
public:
QWidget *widget;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout;
QLabel *label;
QLineEdit *lineEdit;
QPushButton *pushButton;
QTextEdit *textEdit;
void setupUi(QWidget *findButton)
{
if (findButton->objectName().isEmpty())
findButton->setObjectName(QString::fromUtf8("findButton"));
findButton->resize(800, 600);
widget = new QWidget(findButton);
widget->setObjectName(QString::fromUtf8("widget"));
widget->setGeometry(QRect(170, 140, 298, 227));
verticalLayout = new QVBoxLayout(widget);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
verticalLayout->setContentsMargins(0, 0, 0, 0);
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
label = new QLabel(widget);
label->setObjectName(QString::fromUtf8("label"));
horizontalLayout->addWidget(label);
lineEdit = new QLineEdit(widget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
horizontalLayout->addWidget(lineEdit);
pushButton = new QPushButton(widget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
horizontalLayout->addWidget(pushButton);
verticalLayout->addLayout(horizontalLayout);
textEdit = new QTextEdit(widget);
textEdit->setObjectName(QString::fromUtf8("textEdit"));
verticalLayout->addWidget(textEdit);
retranslateUi(findButton);
QMetaObject::connectSlotsByName(findButton);
} // setupUi
void retranslateUi(QWidget *findButton)
{
findButton->setWindowTitle(QCoreApplication::translate("findButton", "TextFinder", nullptr));
label->setText(QCoreApplication::translate("findButton", "Keyword", nullptr));
pushButton->setText(QCoreApplication::translate("findButton", "Find", nullptr));
} // retranslateUi
};
namespace Ui {
class findButton: public Ui_findButton {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_TEXTFINDER_H