Porting a Windows compiled QT application to Linux? - c++

I created this simply application in Qt4 and would like to test it on RH Linux distro. The distro has both QtCore "Qt4" and Qt3 installed. I cannot add or delete any of these Qt versions, but would like to work with what's available.
I have an error compiling my windows based Qt program "Qt4" in Linux .
First question :
- How do I compile my compile in Linux without QT creator "only Qt libraries" are installed, what I did is get the .pro file from windows and typed qmake . , the errors are :
WARNING : Found potential symbol conflict of mainwindow.cpp (mainwwindow.cpp) in SOURCES
WARNING : Found potential symbol conflict of mainwindow.h (mainwwindow.cpp) in HEADERS
WARNING : Found potential symbol conflict of dialog.cpp (dialog.cpp) in SOURCES
WARNING : Found potential symbol conflict of dialog.h (dialog.h) in HEADERS
How can I modify qmake to specify the version of Qt
Thank you.
Below is my .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TestTool
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
dialog.cpp
HEADERS += mainwindow.h \
dialog.h
FORMS += mainwindow.ui \
dialog.ui
The compilation error is :

Try using the Qt4 version of qmake explicitly:
/usr/lib64/qt4/bin/qmake -o Makefile TestTool.pro

Related

Empty QT GUI crashes after linking DLLs

For my project i need a GUI and library called "STM32CubeProgrammer CLI".
They include some example C++ projects with VS and QT (both only command line, no GUI).
I'm able to compile and work with them.
In the next step I created a QT Widgets Application and add the STM library but the program crash instantly.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
$$PWD/../../../include/CubeProgrammer_API.h \
$$PWD/../../../include/DeviceDataStructure.h \
FORMS += \
mainwindow.ui
#comment out that line and the programm works
win32: LIBS += -L$$PWD/../../../lib/ -lCubeProgrammer_API
INCLUDEPATH += $$PWD/../../../include
DEPENDPATH += $$PWD/../../../include
This is the main.cpp I don't edit any "window" or other files, I don't even use a function of the dll.
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
The linker find the dlls, but the program only crashes if I'm using a GUI, a simple cmd program dont crash. Just for fun I added Qlibrary, but the program crashes befor.
I'm using qmake, QT 5.14.2 MinGW-32bit and QT Creator 4.11.1.

Add network to Qt Project

I try to use the QtNetwork library and added all dependencies for it in the .pro file. But when I compile my code Qt Creator fails in building the project and claims
C1083: Include "QTcpSocket": No such file or directory - telnet.h:4
I thought adding network to the .pro file would be enough?
networkmonitor.pro
#-------------------------------------------------
#
# Project created by QtCreator 2017-07-24T13:18:19
#
#-------------------------------------------------
QT += core gui network charts
# greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = networkmonitor
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp \
telnet.cpp
HEADERS += \
mainwindow.h \
telnet.h
FORMS += \
mainwindow.ui
telnet.h
#ifndef TELNET_H
#define TELNET_H
#include <QTcpSocket>
#include <QTcpServer>
#include <QDebug>
class Telnet
{
public:
Telnet();
void sendValues(QString _ip, int _port, QString _message);
private:
QTcpSocket *socket;
};
#endif // TELNET_H
Normally this means you just forgot to re-run qmake

linux : make boost work with Qt Creator (undefined reference)

I've been trying to make boost work with my current IDE : Qt Creator. I've done everything that's written in this topic : Boost with Qt Creator and Linux and many others, but I still have this error :
/usr/include/boost/test/unit_test_suite.hpp:228: erreur : undefined reference to `boost::unit_test::framework::master_test_suite()'
and many others that follow
my base code is this one :
#define BOOST_TEST_MODULE MyTest
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( my_test )
{
BOOST_CHECK( true );
}
which I got from this small tutorial : http://www.boost.org/doc/libs/1_41_0/libs/test/doc/html/tutorials/hello-the-testing-world.html
My .pro looks like this :
QT += testlib
QMAKE_CXXFLAGS += -std=c++11
OTHER_FILES += \
...
SOURCES += \
...
HEADERS += \
...
LIBS += \
-lboost_system
with files instead of "..."
I've done the
sudo apt-get libboost-all-dev
For information, I'm using Qt Creator 3.6.0 and Qt 5.5.1 on kubuntu 14.04 LTS
What should I do ? I hope to find an answer
Thanks in advance and tell me if I forgot to mention something
Thanks #cv_and_me for the answer :
The error was that I was not including the good library.
LIBS += \
-lboost_system
should be replaced by
LIBS += \
-lboost_unit_test_framework
I made the error to belive that boost was only for unit testing, but it could do a lot more, so we have to add the right part of boost that we will be using (in my case, the unit testing framework).
(for people at the same stage than this post, I then used this tutorial for making a good project structure, separating unit tests and the app : http://dragly.org/2014/03/13/new-project-structure-for-projects-in-qt-creator-with-unit-tests/)

Qt Creator - OpenCV - undefined reference/can't find libraries

Windows 7
Qt 5.4.0
OpenCV 2.4.10
Mingw 4.9.1
I'm trying to create a simple Hello World app, to test if Qt is working with OpenCV. Besides the stuff created by default, the code is
#include <opencv/cv.h>
#include <opencv/highgui.h>
(...)
cv::Mat image= cv::imread("pic.jpg");
cv::namedWindow("Test picture");
cv::imshow("Test picture", image);
cv::waitKey(1000);
(...)
However, I'm having trouble linking libraries. At first I've set the paths to *.dll.a files manually
INCLUDEPATH += C:/opencv/my_build/install/include
INCLUDEPATH += C:/opencv/my_build/install/include/opencv
INCLUDEPATH += C:/opencv/my_build/install/include/opencv2
LIBS += -LC:/opencv/my_build/install/x86/mingw/lib \
-llibopencv_core2410 \
-llibopencv_highgui2410
etc etc
But then I'd get a cannot find -llibopencv_<lib>2410 error. I've even used Qt Creator's "Add library" function (Projects -> rightclick -> add library), the result is the same. That error only goes away if I change -llibopencv_<lib>2410 to -opencv_<lib>2410. Which from my understanding is weird, as the "l" argument is missing.
Even though that error goes away, a bunch of others replace it, as I get undefined reference to cv::EVERYTHING error. I've looked around, found solutions to either problem, but solving one leads to the other and vice versa.
I'm fairly sure the OpenCV build is not at fault - I've already completed a pretty big console-ish app using it with Code::Blocks.
My current *.pro file :
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:/opencv/my_build/install/include
win32: LIBS += -L$$PWD/../../../../../../OpenCV/my_build/install/x86/mingw/lib/ -llibopencv_core2410
INCLUDEPATH += $$PWD/../../../../../../OpenCV/my_build/install/x86/mingw
DEPENDPATH += $$PWD/../../../../../../OpenCV/my_build/install/x86/mingw
win32: LIBS += -L$$PWD/../../../../../../OpenCV/my_build/install/x86/mingw/lib/ -llibopencv_highgui2410
INCLUDEPATH += $$PWD/../../../../../../OpenCV/my_build/install/x86/mingw
DEPENDPATH += $$PWD/../../../../../../OpenCV/my_build/install/x86/mingw
How to correctly link the OpenCV libraries to Qt Creator? Am I missing something?
edit: I've rebuilt the whole damn thing and it still doesn't work. God damn it.
When specifying library, you need to exclude the 'lib' part:
LIBS += -LC:/opencv/my_build/install/x86/mingw/lib \
-lopencv_core2410 \
-lopencv_highgui2410
Frankly, I have little idea of what went wrong. I've edited the environment PATH variable, twice, to include the OpenCV build. Maybe I've made a typo the first time. It now looks like this:
C:\MinGW\bin;C:\OpenCV\my_build\install\x86\mingw\bin;C:\Qt\5.4.0\5.4\mingw491_32\bin;
My *.pro file also looks different.
QT += core
QT -= gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += C:/OpenCV/qtbuild//install/include
LIBS += "C:/OpenCV/qtbuild/install/x86\mingw/lib/*.a"
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I've change +=gui to -=gui and added CONFIG -= app_bundle. The INCLUDE and LIBS paths are also different now - I won't be changing them out of an irrational fear something will go horribly wrong again.
And lastly, I've simply removed the previous project and made a new one. Maybe something else got corrupted?
Anyway, it works now, after doing these things.

SYSTEMTIME in qt

I am a bit stuck at the moment with a little sample project that I would like to run to test some cryptology that I want to use in a main project.
Basically I am using the latest Qt Creator and I have created a simple window dialog. Furthermore, I would like to test the PBKDF2 implementation through CkCrypt2
So what I have done is downloading the X64 version of the library and added it to my project folder. I then told my Qt project to use an external library, the final .pro file looks like this:
#-------------------------------------------------
#
# Project created by QtCreator 2013-06-09T18:09:44
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = crypt2test
TEMPLATE = app
SOURCES += main.cpp\
m
ainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libs/ -lChilkatDbgDll_x64
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libs/ -lChilkatDbgDll_x64d
else:unix: LIBS += -L$$PWD/libs/ -lChilkatDbgDll_x64
INCLUDEPATH += $$PWD/include
DEPENDPATH += $$PWD/include
I can successfully load the library but I cannot start the application.
My mainwindow.cpp looks like this:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "CkCrypt2.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
CkCrypt2 crypt;
bool success;
success = crypt.UnlockComponent("Just some random text ");
if ( !success )
{
qDebug() << "Not successfully unlocking the library";
}
}
MainWindow::~MainWindow()
{
delete ui;
}
The error message I get in the compiler is:
c:\qt\qt5.0.2\tools\qtcreator\bin\crypt2test\include\CkString.h:127: error: C2061: syntax error : identifier 'SYSTEMTIME'
c:\qt\qt5.0.2\tools\qtcreator\bin\crypt2test\include\CkString.h:129: error: C2061: syntax error : identifier 'SYSTEMTIME'
C:\Qt\Qt5.0.2\Tools\QtCreator\bin\crypt2test\include\CkCrypt2.h:429: error: C2061: syntax error : identifier 'SYSTEMTIME'
Looking into the files I see:
void appendDateRfc822(SYSTEMTIME &sysTime);
void appendDateRfc822Gmt(SYSTEMTIME &sysTime);
// GETSIGNATURESIGNINGTIME_BEGIN
bool GetSignatureSigningTime(int index, SYSTEMTIME &outSysTime);
// GETSIGNATURESIGNINGTIME_END
Okay, so it is complaining about the SYSTEMTIME construct. So I look up the error C2061
Basically it says:
The compiler found an identifier where it wasn't expected. Make sure
that identifier is declared before you use it.
Which makes sense, so I look up the SYSTEMTIME and try to do :
#include <windows.h>
But that leads to many more errors in the windows.h file itself.
I use the MS Visual C++ compiler in Qt. Even though I use qmake. I am very new to this and I do not understand it all yet. Furthermore, I have no idea how to fix this, because including the windows.h does not help.
What seems to be the problem here ? Is this an issue regarding my compiler or the constulation that I use a third party app which library is compiled with MS Visual C++ and I am now trying to use this on my Windows machine in Qt with a Windows Visual C++ compiler ?
For any help I am gratefully thankful!
EDIT1:
Actually, after a clean all and qmake and build project I have now different errors and none were found in the Windows.h as previously stated. Since there were so many I have made a screenshot: http://i.imgur.com/B8EoENB.png
EDIT2:
I have adjusted the library that I include. Before this I was using the multi-threaded library of CkCrypt in the Debug mode. I have now included the single realease library. Which is located in the same directory.
When including windows.h I got the errors that things were already defined. So I removed the line again. With this result: http://i.imgur.com/z415txR.png
This shows at the bottom that MSVCRT conflichts with other library. It mentions to use NODEFAULTLIB:library but I am not to sure how to do that. Will google and keep this up to date as I process.
Many years ago, Chilkat was originally developed for the Windows platform only, and used SYSTEMTIME for this reason. In the last 5 years (approx) Chilkat is cross-platform, and SYSTEMTIME no longer makes sense. To cope with the issue, there is a "SystemTime.h" header in the same directory as the CkCrypt2.h header file. You could include this to solve the problem. (However, if WIN32 is defined, you'll probably need to edit SystemTime.h to remove the #ifdef.)
In any case, the methods using SYSTEMTIME are going to be deprecated. For any method or property that uses SYSTEMTIME, there should be a newer alternative method/property that instead uses CkDateTime.
Finally, Chilkat will test with Qt so that for the next version, (hopefully) Qt out-of-the-box will compile without any pitfalls.