UI_project.h not found for QT project - c++

I made a QT GUI project in VS 2019. It ran perfectly through VS. Copied the entire project files directory to Linux partition. Ran qmake -project in the directory containing the 'test2.sln' file to create a 'test2.pro' file. Opened the '*.pro' file through QT Creator. It imported everything fine. But, when building it it errors out saying "ui_test2.h file not found".
The test2.pro contains:
TEMPLATE = app
TARGET = test2
INCLUDEPATH += .
DEFINES += QT_DEPRECATED_WARNINGS
HEADERS += test2/test2.h test2/x64/Release/uic/ui_test2.h
FORMS += test2/test2.ui
SOURCES += test2/main.cpp test2/test2.cpp test2/x64/Release/rcc/qrc_test2.cpp
RESOURCES += test2/test2.qrc
What should I do to fix this?

1) remove folder with build (rm -r nameOfFolder)
2) rename your UI file (test2.ui -> mainwindow.ui) for example
3) check out name of own class and name of qt class in UI file (you can open it via vim or nano)
After that try to rebuild your project!
I hope you'll have done this with good results!

Related

Where do I put the QT5 clone in this project

This is my first time every using C++ so please go easy on me. I have about 7000 hours of Python experience so I'm not completely clueless. I'm trying to read the code written for the Collatinus software found here. collatinus. It seems that the initial file is this:
VERSION = "11.2"
DEFINES += VERSION=\\\"$$VERSION\\\"
DEFINES += MEDIEVAL
TEMPLATE = app
TARGET = collatinusd
INCLUDEPATH += . src
DEPENDPATH += .
DESTDIR = bin
OBJECTS_DIR= obj/
MOC_DIR = moc/
QMAKE_DISTCLEAN += $${DESTDIR}/collatinus
CONFIG += console
CONFIG -= app_bundle
CONFIG += release_binary
QT += core
QT -= gui
QT += xmlpatterns
QT += network
I've downloaded qt from qt and got the open source qt5. Now I cannot figure out where to put the file. I have tried putting it in the same folder as the above mentioned code. I have also tried putting in the folder marked src. In the src folder there are many files which use QT but it seems like the files are supposed to be taken out of the QT folder. For example in this file we have the syntax on line 28
#include <QDebug>
The QDebug file is in the QT folder. But when I put the qt folder in either the topmost folder or the src folder I get the error message:
fatal error: 'QtCore' file not found
#include <QtCore>
So the file structure is as follows:
/collatinus-daemon
collatinus.pro (and other files)
//src
flexion.cpp (and other files)
So where do I put the qt folder? Also, I renamed it qt from qt5 since the syntax had the line:
QT += core
###################
Ok, I've got the QT creator up and running. Here is the pro file
QT += network widgets
QT += core
QT -= gui
TARGET = Client_C11
VERSION = "1.0"
#CONFIG += console
#CONFIG -= app_bundle
CONFIG += release_binary
TEMPLATE = app
SOURCES += src/client_main.cpp
OBJECTS_DIR= obj/
MOC_DIR = moc/
unix:!macx:DESTDIR = bin
macx:{
# Commandes spéciales pour déployer l'application sur Mac.
# J'ignore s'il faut l'équivalent pour Linux ou Windows.
# Philippe. Octobre 2016
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.8
ICON = collatinus_bw.icns
deploy.commands = macdeployqt Client_C11.app
QMAKE_EXTRA_TARGETS += deploy
}
Here are some screenshots of my folders:
And here is the error message I'm getting:
Here also is the code for the client main
#include <QCoreApplication>
#include <iostream>
#include <QtWidgets>
#include <QtNetwork>
class QTcpSocket;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString req = "";
if (argc > 1)
{
int i = 1;
while (i < argc)
{
QString suite(argv[i]);
req += " " + suite;
i++;
}
}
else req = "-?"; // pour afficher l'aide.
QTcpSocket * tcpSocket = new QTcpSocket();
tcpSocket->abort();
tcpSocket->connectToHost(QHostAddress::LocalHost, 5555);
QByteArray ba = req.toUtf8();
tcpSocket->write(ba);
tcpSocket->waitForBytesWritten();
tcpSocket->waitForReadyRead();
ba = tcpSocket->readAll();
tcpSocket->disconnectFromHost();
tcpSocket->close();
QString rep(ba);
std::cout << rep.toStdString();
a.quit();
}
I don't understand what I'm supposed to do with qmake and cmakelists
Where do I put the QT5 clone in this project
You don't :)
Qt installations up to 5.14 are not relocatable. That means that once Qt is installed, if you move it to another path, it'll break. Just don't mess with it: once installed, you leave it alone, and it'll work just fine.
Qt source code has to be built before it can be used. I presume that you downloaded the source code and want to stick it into the project and build the two that way. It's not designed to work that way at all.
Qt build requires several other tools to be installed (iirc python, ruby, perl), and other optional dependencies to get the full feature set, and if it fails for whatever reason, figuring it out is unnecessary effort initially. So it's best to start with pre-built Qt.
I've downloaded qt from qt and got the open source qt5. Now I cannot figure out where to put the file.
Downloading "qt" doesn't mean much, since everyone means something else by that. If you've downloaded the source code, then delete it - last thing you want is to mess with compiling Qt right now.
Normally, Qt is installed using an installer, so what you'd download is an executable installer, and use that to select the Qt components you want to install. On Windows, pick the mingw-based Qt version, since that also installs the build environment (compilers) if you don't have them already. Otherwise you'd use the MSVC-based version if you got MSVC installed on Windows.
On Unix, you'd want to install Qt using the "native" package manager - one that came with your linux distribution, or macports (really preferred) on MacOS.
Once Qt is installed, you'd use Qt Creator IDE to open the collatinus project (its .pro file). And everything will "just work" from that point onwards - it'll let you build it and run whatever executable targets it produced. Of course you can build from the command line, but for a beginner it's just an extra layer of complication and unnecessary.
In any case, the .pro file you refer to would be processed by qmake to generate the build system that builds the project. qmake itself is the means you use to select what Qt version you build with: there's one qmake per each Qt installation. So, after qmake has ran, you'd make the thus-configured build, and there'll be no problems with finding Qt headers. It's the job of qmake in that case to set everything up so that the compiler will be told where to find Qt. You are not expected to have to mess with it manually.
If there's a CMakeLists.txt file in the project, you'd probably prefer to use that instead of qmake, since cmake is a widely used tool with lots of knowledge available online, whereas qmake is now obsolete. Still, older projects may only supply a .pro file that needs to be used with qmake and not cmake.
Your question doesn't nearly provide enough detail for a more focused answer - please tell us exactly what you did, and what Qt elements you installed (whether using Qt Installer program, or using a unix package manager).

Qt c++ Add module

I have a problem with c++ and Qt.
I am working on a Linux Mint system and I installed Qt in my user folder. This results having the include folder here:
/home/username/Qt5.3.1/5.3/gcc_64/include/
Now, whenever I try do run the commands:
qmake -project
qmake
make
I get an error for the modules, it says for example:
QApplication: No such file or directory
I tried a workaround by adding the line Qt+=Widgets in the .pro file but this did not work.
So I manually copied QApplication from:
/home/username/Qt5.3.1/5.3/gcc_64/include/QtWidgets
to its parent folder:
/home/username/Qt5.3.1/5.3/gcc_64/include/
and this worked, but it is kinda "brutally" forced.
How could I solve this?
QT += core gui opengl widgets
TEMPLATE = app
TARGET = cw
INCLUDEPATH += /home/username/Qt5.3.1/5.3/gcc_64/include/
Try to include path, by adding INCLUDEPATH += <your path> in your .pro project file.
In project file you should add Qt+=widgets instead of Qt+=Widgets.
Add #include <QtWidgets> on top of your main.cpp.

Standalone Application Qt

I have a Qt application that needs a specific folder and some files. This folder is now located inside the project folder. Is there any way to make this folder be "generated" when I use the make command to create the Standalone version of the program.
I was thinking about changing something in my .pro file but could not figure out any solution that way.
The folder contains some .lua code that I need to make the software work properly if the user select some functionalities.
One solution that copy these resources to destination folder the binary installed via qmake. Please refer to the link enter link description here
Some answers are out-of-date but inspire enough.
Possible solution(see http://doc.qt.io/qt-5/qmake-advanced-usage.html):
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
SOURCES += main.cpp
lua_dir.target = .makedir
lua_dir.commands = test -d lua_dir || mkdir lua_dir
QMAKE_EXTRA_TARGETS += lua_dir
PRE_TARGETDEPS += .makedir
You should replace lua_dir.commands = test -d lua_dir || mkdir lua_dir with appropriate to you command, I use bash command intepreter here.
you can change DESTDIR qmake variable to compile binary file straight to specified directory.
you can use INSTALLS:
someTarget.path = $$OUT_PWD/MyFolder
someTarget.files = $$PWD/SomeDirToCopy/*
INSTALLS += someTarget
this will copy all files from ProjectDirectory/SomeDirToCopy folder to BuildDirecory/MyFolder after you run make install in build directory.

qt build output directory being totally ignored

i've been using qt recently and was organizing some projects into a Subdirs to begin a larger project, and went to manipulate the pro files so as to place my build files where i want them. However, the changes i make to any of them are being ignored. I have a main project that compiles to an executable, and then two other projects that compile to DLL's. I would like for the executables and libraries to end up in the same directory, where the subdirs pro file is located. Here is the pro file for my subdirs that i've tried:
TEMPLATE = subdirs
SUBDIRS += \
MainWindow \
FileLoader
Debug:DESTDIR = $$_PRO_FILE_/debug
Debug:OBJECTS_DIR = $${DESTDIR}/.obj
Debug:MOC_DIR = $${DESTDIR}/.moc
Debug:RCC_DIR = $${DESTDIR}/.rcc
Debug:UI_DIR = $${DESTDIR}/.ui
Release:DESTDIR = $$_PRO_FILE_/release
Release:OBJECTS_DIR = $${DESTDIR}/.obj
Release:MOC_DIR = $${DESTDIR}/.moc
Release:RCC_DIR = $${DESTDIR}/.rcc
Release:UI_DIR = $${DESTDIR}/.ui
After that, i put that same path block in all three of the subprojects pro files, and still all the build files end up in a directory in my Qt Projects directory called "build-Chromatic-Desktop_Qt_5_1_1_MSVC2010_32bit-Debug" (Chromatic is the name of the project). Can someone help me wrangle my pro files to do make this stuff where i want it? Again, i want all the build files for all projects in the directory where the subdirs pro file is.
Instead of using _PRO_FILE_ you should use _PRO_FILE_PWD_ because the first variable contains the path to the project file in use and the second contains the path to the directory containing the project file in use.
In Qt Creator you should deselect the Shadow build checkbox: "By default, Qt Creator builds projects in a separate directory from the source directory, as shadow builds. This keeps the files generated for each build and run kit separate. If you only build and run with a single kit, you can deselect the Shadow build checkbox."

Installing files using qmake: how to get the executable too?

I'm building my app with qmake.
my project.pro file looks something like:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += [all source files]
HEADERS += [all headers]
After a build, I want "make install" to copy everything required in a subfolder, so I added the following:
package.path = $${OUT_PWD}/package
package.files += myapp.exe myapp.ini [other dlls]
package.CONFIG = no_check_exist
INSTALLS += package
I cannot have in any way my compiled binary to be copied alongside; I prefixed it with $$OBJECTS_DIR/ and others, but I can't find the right variable containing the path to the build directory!
It seems these variables are meant as a way to change qmake's behaviour, for example to change the build directory. I don't want to change it; I want to access it!
Is there any other variable I could use? Basically, I want to put in "package.files" the full path to the compiled executable binary.
Thanks!
qmake puts the complied executable (or library) in the location pointed to by DESTDIR.
Usually, when I want to put the binary and support files, I will set DESTDIR to the location I want to install stuff, then set any INSTALLS.path to DESTDIR.
DESTDIR = $${OUT_PWD}/package
package.path = $${DESTDIR}
package.files += myapp.exe myapp.ini [other dlls]
package.CONFIG = no_check_exist
INSTALLS += package