0

I have a QT Application, but as I undestand, the ui file is not found. All of the listed files are located in the same directory, the projects root folder. I'm using Clion as IDE and have created the ui with Clion. My CMakeLists.txt:

cmake_minimum_required(VERSION 3.9)
project(Restclient)

find_package(cpprestsdk REQUIRED)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)


find_package(Qt6 COMPONENTS
        Core
        Gui
        Widgets
        REQUIRED)

add_executable(Restclient main.cpp rest/Client.cpp rest/Client.h rest/User.cpp rest/User.h rest/Message.cpp rest/Message.h rest/LoginException.h login.cpp login.h login.ui)
target_link_libraries(Restclient
        Qt::Core
        Qt::Gui
        Qt::Widgets
        cpprestsdk::cpprest
        )

The Login.ui is located in the projects root folder, the corresponding Login.h :

//
// Created by simon on 28.04.22.
//

#ifndef RESTCLIENT_LOGIN_H
#define RESTCLIENT_LOGIN_H

#include <QWidget>
#include <QPushButton>
#include <QLineEdit>


QT_BEGIN_NAMESPACE
namespace Ui { class Login; }
QT_END_NAMESPACE

class Login : public QWidget {
Q_OBJECT

QPushButton * loginButton;
QLineEdit * passwordInput;
QLineEdit * usernameInput;

public slots:
    void buttonPressed();

public:
    explicit Login(QWidget *parent = nullptr);

    ~Login() override;

private:
    Ui::Login *ui;
};


#endif //RESTCLIENT_LOGIN_H

And login.cpp

#include "login.h"


Login::Login(QWidget *parent) :
        QWidget(parent), ui(new Ui::Login) {
    ui->setupUi(this);
    QObject::connect(loginButton, &QPushButton::clicked, this, &buttonPressed);
}

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

void Login::buttonPressed() {
    //todo process login
}

My error is: invalid use of incomplete type 'class Ui::Login' and no 'forward declaration of 'class Ui::Login'. I'm a java dev who is new to cpp, so some help would be nice.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • 1
    Your login.cpp file should include the `ui_Login.h` file. It should likely be generated in the build folder tree and not in the source folders. I don't use CLion but use CMake + Visual Studio and Qt – drescherjm Apr 28 '22 at 20:19
  • So by including it, the error is that it is not found in the src folder. How do I specify the location? – saltycoder815 Apr 29 '22 at 06:40
  • 1
    [https://stackoverflow.com/questions/566785/cmake-add-build-directory-to-include-path](https://stackoverflow.com/questions/566785/cmake-add-build-directory-to-include-path) – drescherjm Apr 29 '22 at 11:49

0 Answers0