Where do I put the QT5 clone in this project - c++

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).

Related

UI_project.h not found for QT project

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!

Qt not working with VTK libraries

Hi stackoverflow family
I'm trying to get vtk working with qt. I should admit that I'm a newbie, so go easy. I'm trying to learn c++ for myself and have chosen the following configuration to get me started;
OS: Windows 7 ultimate
toolkit: QT 5.3.2
IDE: QT Creator 3.2.1
VTK: 6.3.0
I downloaded and extracted the VTK to "C:\vtk-6.3.0" on my computer. I followed the instructions given on VTK's website to build VTK with cmake. I gave cmake the location of the source "C:/vtk-6.3.0" and specified a place to build the libraries "C:/vtk/bin".
Thinking everything had gone smoothly, I proceeded with the simplest example I could get away with, an example without a ui. I got the example from here
RenderWindowNoUiFile.cxx
#include <QApplication>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <QVTKWidget.h>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QVTKWidget widget;
widget.resize( 256, 256 );
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection( sphereSource->GetOutputPort() );
vtkSmartPointer<vtkActor> sphereActor =
vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper( sphereMapper );
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor( sphereActor );
widget.GetRenderWindow()->AddRenderer( renderer );
widget.show();
app.exec();
return EXIT_SUCCESS;
}
I added my .pro file manually
RenderWindowNoUiFile.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = RenderWindowNoUiFile
TEMPLATE = app
SOURCES += RenderWindowNoUiFile.cxx
INCLUDEPATH += C:\VTK\bin
I observed that qt has underlined all of the header files and when I ran the program and I got the error
Projects\RenderWindowNoUiFile\RenderWindowNoUiFile.cxx:3: error: vtkSmartPointer.h: No such file or directory
#include <vtkSmartPointer.h>
^
Please what I'm I doing wrong?
When I searched for any of the header files, I find each in a different location in the "C:\vtk\bin" or "C:\vtk-6.3.0" folder.
Please how do I solve this problem? Can I get all of the header files in a single folder so that I can refer to it in the .pro file?
For example if I can get all the header files in a directory called "C:\vtk\header", then I can refer to it in my .pro file as INCLUDEPATH += C:\vtk\header
You kind of touched on it with your comment "can I get all the headers in one directory" That is the setting INCLUDEPATH, but you have it set incorrectly.
There are a few issues in what you are doing.
First, your INCLUDEPATH is incorrect. It should be set to the "include" directory of the files that you've installed.
Second, you haven't included the library in your build- so even if your include files resolved, you would get link errors. This is because you haven't specified where the binary library files are.
Third, you didn't specify if your VTK build was static or dynamic. I'll assume this is dynamic. IF you don't know what this means, please look that up. The big difference is: do you need to also copy a .dll file to where your program is running from. If you have dynamic, the answer is yes.
About the comment a out the install target: with cmake you can set an option to change where it installs the binaries to. So the process goes like this with cmake:
1) Get the sources unpacked to a directory that you like.
2) Run cmake build folder (which you set to bin). What you did was confusing, because the build folder will contain everything: not just binaries, but headers and other install stuff. I usually call it "build"
3) Once cmake configures it may prompt for more configuration. This is where you may want to configure Qt for VTK. In this step you tell cmake where the Qt cmake folders are, so that you can configure VTK to build Qt stuff
4) Now you can change the default install path. By default, when you build the INSTALL project with visual studio (I'll describe below) it installs somewhere in program files. You can change this by setting CMAKE_INSTALL_PREFIX to whatever you want. For example: C:\VTK\install
5) Click generate to generate the visual studio project files or Make files, depending on your build configuration.
6) For visual studio: open the solution in the build directory and build all. When this completes, to install the files (#4) run the INSTALL project.
7) For Make files: run make (if you have multiple cores, use -jX where X is twice number of cores) then make install (don't use -j with make install)
Ok at this point you've compiled and installed the VTK distribution. Now you should fix your paths in your Qt .pro file.
For example:
INSTALLPATH+=C:/VTK/install/include
I don't know which libs you need, but below you should see the pattern:
LIBS+=-LC:/VTK/install/lib \
-lvtkRenderingCore-6.3
Now after this, since you have a dynamic build you need to copy the .dll files next to the exe file that you are creating from your Qt project.
Good luck!
If you use mingw with qt ,you have to compile source of vtk with mingw as you know.In that web page they use vs so I want to warn you about it.When you configure vtk source with cmake you should check "Module_vtkGUISupportQt" and "Module_vtkGUISupportQtOpenGL" options to able to work with qt.Also you have to do some config in Run & Build Options in Qt such as selecting compiler, kits etc.
Notice that choosing a compiler which is released after the release date of the library(in this case vtk) may prevent you from suffering of much errors.

Qt 5.3. QtWidgets: No such file or directory #include <QtWidgets>

I want to compile Qt example. I get error QtWidgets: No such file or directory #include
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - does not help
QT += widgets - does not help
INCLUDEPATH += /opt/Qt/5.3/Src/qtbase/include/ - does not help
Qt 5.3. Ubuntu 14.04 x64.
You need to double check that you completed all these steps:
Module installed
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
You re-run the Qt 5 qmake.
Having said that, I would like to remind you that including the whole module is not a good idea as it includes all the widgets related things. Try to narrow it down to the headers that you really need.
As you noticed Qt directory structure changed between Qt4 and Qt5. QWidget header moved to a QtWidgets directory. Try adding
INCLUDEPATH += /opt/Qt/5.3/Src/qtbase/include/QtWidgets
If that does not help try finding the header manually using
find /opt/Qt/5.3/Src/qtbase/ -name QWidget
and and the directory it is in to INCLUDEPATH
Edit based on comment from Final Contest.
I agree that workarounds usually are a bad idea. To test where QT your installation looks for qt5 headers and libraries. Create a minimal project.
#include <QApplication>
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget w;
w.show();
app.exec();
}
Generate a project and add QT += widget
/opt/Qt/5.3/Src/qtbase/bin/qmake -project
Project file
######################################################################
# Automatically generated by qmake (3.0) Thu Jul 10 13:05:17 2014
######################################################################
TEMPLATE = app
TARGET = so_qtwidgets
INCLUDEPATH += .
QT += widgets
# Input
SOURCES += main.cpp
Generate a make file
/opt/Qt/5.3/Src/qtbase/bin/qmake
The interesting parts widget flag adds:
In my case -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtGui to INCPATH
-DQT_WIDGETS_LIB to DEFINES variable.
-lQt5Widgets -lQt5Gui to libs.
The only part which should differ is the paths to QtWidgets and QtGui. If these a wrong the I would try reinstalling Qt.
Check what your .pro file looks like before you run "make". I found that the command "qmake -project" auto generated a .pro file that caused this same error. I now compiled my qt project via the following commands and the error went away:
qmake my_project.pro
make
This all looks very much like the wrong way round and I did have the same problem temporarily with 5.6 but the answer could be a whole lot simpler.
If you're loading a lot of examples you may arrive at the editor or whatever you were at last, first. If the example's been loaded for the first time it'll need to be 'configured' which is under the projects side-tab which should present you with 'Configure' rather than 'Build & Run'. That it doesn't always jump straight there is a flaw, but then so's the inclusion of examples with no support by default (Desktop OpenGL and iOS for two).
Until that's done it'll not resolve any dependencies outside the immediate project as the libraries used depend on which compiler/target is used (eg. MSVS, GNUCC, MinGW, 32/64bit).

Qt Libraries cannot be found on Mac

I'm having issues setting up the Qt environment on Mac 10.9.1. If I just try to compile a C++ file with the standard g++ source.cpp -o output Then none of the Qt Libraries are found. For instance if I have
#include <QString>
Then I will get the error fatal error: 'QString' file not found
I have installed Qt 5.2.1 and added it to my PATH variable, so now when i make the project using qmake -project, qmake -spec macx-g++ and then make
I get the error saying that my version of Mac OSX is not supported. I have to use Qt for my college assignment, please can someone help me set this up.
Any help would be appreciated.
Mavericks is definitely supported by Qt 5. It is not supported by Qt 4 so far; trojanfoe made a typo in his comment (nomen est omen?).
Your mistake is using the wrong make spec. Qt 5 uses clang, not gcc. Thus the following works for me (without setting any paths):
~/Qt5.2.1/5.2.1/clang_64/bin/qmake -project
~/Qt5.2.1/5.2.1/clang_64/bin/qmake -spec macx-clang
make
You can have multiple Qt versions existing side by side, there's no reason to uninstall anything when you get a new Qt version installed.
A small self-contained example would be below. Put it in a simple folder. To build, do:
~/Qt5.2.1/5.2.1/clang_64/bin/qmake -spec macx-clang
make
You do not want to regenerate the .pro file by invoking qmake with -project argument. The project generation is just to give you a simple skeleton, you're only supposed to do it as a convenience when importing third-party code.
Note that by definition if you use any visible GUI elements (windows, message boxes, etc), it's not a console application anymore as far as Qt is concerned.
# simple.pro
TEMPLATE = app
QT += widgets
# Creates a simple executable instead of an app bundle
CONFIG -= app_bundle
SOURCES += main.cpp
// main.cpp
#include <QApplication>
#include <QMessageBox>
int main(int argc, char ** argv)
{
// It is an error not to have an instance of QApplication.
// This implies that having an instance of QCoreApplication and QGuiApplication
// is also an error.
QApplication app(argc, argv);
QMessageBox::information(NULL, "Get This!", "Something's going on");
}

Problem installing QCA-OSSL (part of the Qt Cryptographic Architecture) plugin on Windows 7

I have been trying to use QCA (Link) on my Windows PC for a couple of days now, works fine on my linux box, just can't get it working with Windows.
So i followed all the instructions for installing QCA and then the ossl plugin for QCA. The QCA works fine but for some reason the plugin isn't showing up in my Qt Creator nor am I able to use some of the functions in the plugin.
I used the qcatool2.exe that comes with QCA to check my plugins using
qcatool2 plugins --debug
and get this error message:
plugin: qca-ossl2.dll: failed to load: The plugin 'C:/Qt/2010.05/qt/plugins/crypto/qca-ossl2.dll' uses incompatible Qt library. Expected build key "Windows mingw debug full-config", got "Windows mingw release full-config"
Now this seems to me as if qt requires the plugin to be compiled in debug mode (as to get the build key to contain debug rather than release) so I added
CONFIG += debug
to my plugin's project file and ran qmake and mingw32-make as usual but this seems to have had no effect.
My project file for the plugin is now:
TEMPLATE = lib
CONFIG += plugin
QT -= gui
DESTDIR = lib
VERSION = 2.0.0
unix:include(conf.pri)
windows:CONFIG += crypto
windows:include(conf_win.pri)
CONFIG += create_prl
SOURCES = qca-ossl.cpp
windows:{
load(winlocal.prf)
isEmpty(WINLOCAL_PREFIX) {
error("WINLOCAL_PREFIX not found. See http://delta.affinix.com/platform/#winlocal")
}
OPENSSL_PREFIX = $$WINLOCAL_PREFIX
DEFINES += OSSL_097
INCLUDEPATH += $$OPENSSL_PREFIX/include
LIBS += -L$$OPENSSL_PREFIX/lib
LIBS += -llibeay32 -lssleay32
LIBS += -lgdi32 -lwsock32
}
!debug_and_release|build_pass {
CONFIG(debug, debug|release) {
mac:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
}
}
CONFIG += debug
Has anyone got any ideas? If you need anymore details just ask, I've tried to be as thorough as possible. Thanks
Tom
I've been struggling with a similar situation: qca-ossl builds fine on linux and not at all on windows. I just hit a breakthrough which might help you as well.
Versions and Patches
qtsdk-2010.05
qca-2.0.3
qca-ossl-r1190163 (from the repository)
openssl-1.0.0b
First of all, if you're using a newer version (0.9.7+, I think) of OpenSsl, you may need to use the qca-ossl version from the repository since it patches some incompatibilities. I also needed to comment out some lines in the new qca-ossl.cpp file dealing with SHA224, SHA256, SHA384, and SHA512 to avoid build errors. I'm using qca-ossl for the ciphers, so I'm not worried about hashing and didn't investigate the errors very much.
Fixing It
The windows build problems were many fold for me, but most of them stem from the shoddy build setup for the windows version of the plugin. It's nice having a little configure script for the linux side of things, but what about windows? We need to do a little extra work.
Some of this extra work is because I've chosen non-standard locations for the support libraries of my application. Qca and OpenSsl both exist within the project's directory structure in a libraries/ directory. My guess is that you've done something similar if you are trying to cross compile your application, but even if you didn't the following should help.
Finding OpenSsl
Qca-ossl wont build very well if it can't find the library it's supposed to connect to... :) So let's specify directly where it is. Comment out the lines relating to winlocal.prf and the changes that stem from it in qca-ossl.pro. We will directly specify where to find openSsl.
TEMPLATE = lib
CONFIG += plugin
QT -= gui
DESTDIR = lib
VERSION = 2.0.0
unix:include(conf.pri)
windows:CONFIG += crypto
windows:include(conf_win.pri)
CONFIG += create_prl
SOURCES = qca-ossl.cpp
windows:{
# Rather than rely on the winlocal.prf file, we will specify the location of the openssl
# by hand when running qmake.
#
# load(winlocal.prf)
# isEmpty(WINLOCAL_PREFIX) {
# error("WINLOCAL_PREFIX not found. See http://delta.affinix.com/platform/#winlocal")
# }
#
# OPENSSL_PREFIX = $$WINLOCAL_PREFIX
DEFINES += OSSL_097
INCLUDEPATH += $$OPENSSL_PREFIX/include
LIBS += -L$$OPENSSL_PREFIX/lib
LIBS += -llibeay32 -lssleay32
LIBS += -lgdi32 -lwsock32
}
!debug_and_release|build_pass {
CONFIG(debug, debug|release) {
mac:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
}
}
Now we have direct access to the $$OPENSSL_PREFIX environment variable in the .pro file. We can set it when we call qmake by doing the following.
qmake.exe "OPENSSL_PREFIX=C:/path/to/openssl-1.0.0b"
You should be able to use backward slashes or forward slashes. Here I choose forward since Qt has deprecated them since 4.7.
Alternatively, you could set the OPENSSL_PREFIX variable directly in the .pro file.
Finding Qca
After comparing the unix and windows makefiles for qca-ossl, oddly enough, it never includes the qca libraries for building or linking! ?!?! This led to an "Undefined interface" error on the Q_INTERFACES(QCAPlugin) line of the opensslPlugin class definition at the end of qca-ossl.cpp.
To avoid this, we will need to explicitly define the include and library paths by hand. Expanding on the qmake line from the last section the final qmake line is as follows.
qmake.exe "OPENSSL_PREFIX=C:/path/to/openssl-1.0.0b" "INCLUDEPATH+=C:/path/to/qca-2.0.3/include/QtCrypto" "LIBS+=-LC:/path/to/qca-2.0.3/lib -lqca2"
"Installing" Qca-ossl
After running the qmake line above and running a plain ol' make, you'll need to install Qca-ossl. You can copy the resulting dll from the lib/ directory to your Qt's plugins directory, which if you're using my versions defaults to C:\Qt\2010.05\qt\plugins\crypto. Alternatively, you can move it to a crypto directory that's at the root level of your project's directory structure such as C:\path\to\my\project\crypto.
I hope this helps!
Actually, you can try this tutorial QCA+OpenSSL on Window. It's work well.
By the way, I can make use of QCA with AES 256 on Window. But i can't use it on Symbian. Any idea to do it?
Related Post