Struggle with QGIS C++ API - c++

I'm trying to create a simple application using QGIS SDK. But currently, I'm stuck with API at very beginning stage.
belows are the env.
Windows 7
MSVC 2015
QGIS SDK (downlaod by OSGeo4w) include:
qgis-dev(3.2.3)
Qt5(5.9)
here is the OSGeo4w directory
here is the OSGeo4w/app directory
And start by create an empty project, property settings:
C/C++ -> General -> Additional Include Directories
C:\OSGeo4W\apps\Qt5\include
C:\OSGeo4W\apps\Qt5\include\QtCore
C:\OSGeo4W\apps\Qt5\include\QtGui
C:\OSGeo4W\apps\Qt5\include\QtWidgets
C:\OSGeo4W\apps\Qt5\include\QtXml
C:\OSGeo4W\apps\qgis-dev\include
C:\OSGeo4W\include
Linker -> General -> Additional Library Directories
C:\OSGeo4W\apps\Qt5\lib
C:\OSGeo4W\apps\qgis-dev\lib
Linker -> Input -> Additional Dependencies
qtmaind.lib
Qt5Cored.lib
Qt5Guid.lib
Qt5Widgetsd.lib
qgis_core.lib
qgis_app.lib
qgis_gui.lib
The test code is quite simple:
main.cpp
#include <QtWidgets/QApplication>
#include <qgsapplication.h>
int main(int argc, char *argv[])
{
QgsApplication a(argc, argv, true);
// QgsApplication::setPrefixPath("C:/path/to/OSGeo4W64/apps/qgis", true);
// QgsApplication::initQgis();
// ImageViewer w;
// w.show();
return a.exec();
}
however, errors occured when I build it,
(1)no instance of constructor "QgsMapUnitScale::QgsMapUnitScale" matches the argument list (qgsrendercontext.h)
(2)"M_PI": undeclared identifier (qgsabstractgeometry.h)
here is the build error messages
Could anyone give me a suggestion?I have some difficulties to understand how the API should work and there is really few doc. and resource about
QGIS C++ developement on internet, even on QGIS offical website.
I appreciate any help, thanks.

Related

Cannot open include file: 'QtWidgets/qtwidgetsglobal.h' on vs2017

[Solved]
Additional include directories should be:
C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include,
not C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include\QtWidgets
as the statement in qapplication.h is "#include <QtWidgets/qtwidgetsglobal.h>"
When I was running this on VS2017(x86) on win10, I got the error below:
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
return 0;
}
fatal error C1083: Cannot open include file: 'QtWidgets/qtwidgetsglobal.h'
The qtwidgetsglobal.h file is just in the directory, but I don't know why VS can't open it.
It seems that compiler can open QApplication(is it the same as qapplication.h?), but can't open the first #include file 'qtwidgetsglobal.h' in QApplication... Why?
I have set the additional include and lib directories in project settings
Additional include directories :
C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include\QtWidgets
Additional lib directories:
C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\lib
I have also installed Qt VS Tools and added the qt version
qt vs tools options
I have also tried the 'winrt_x86_msvc2017'directory, and it came to the same error. I can't find 'msvc2017' directory, there's only 'msvc2017_64'.
Any ideas would be appreciated
Additional include directories should be:
C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include,
not C:\Qt\Qt5.9.3\5.9.3\msvc2017_64\include\QtWidgets
as the statement in qapplication.h is #include <QtWidgets/qtwidgetsglobal.h>

Linking google test to your main project

I am new to the gtest. I have followed a tutorial how to set it up in the VS 2105.
But all that I could find talked about how to build and link gtest.
I am passed that level. The code below runs and passes the first dummy test.
#include "gtest/gtest.h"
TEST(VI, simple) {
EXPECT_EQ(false, false);
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
std::cin.get();
return 0;
}
My question:
How do I exactly hook it up to my project that I want to test?
Both gtest project and my "code" project are in the same solution.
As far as I understood from reading numerous tutorials, I need 2 things:
1) to include my .h of the class I am about to test (easy and done)
2) To compile my "code" project into a static lib and then hook up
the lib to gtest project so I can create and test objects from the
"code" project.
I am struggling with the point 2. How exactly do I go about it?
Thank you for help in advance.
Add a new empty Win32 project to your solution, in its properties select Project Type "static library (.lib)"
Move all your sources except the main() function to that project
Add a reference to the .lib project to both your main application project and the google test project

How to include jxcore c++ library "jx.h" in qt applications?

This is the sample code I am trying execute in Qt Creator. I have included all the JX libraries in Qt. The JX c++ code works outside Qt well but I want to make it work inside Qt. Please review the code and suggest me a way to achieve this.
Currently I am getting errors such as "undefined reference to `v8::Locker::Locker(v8::Isolate*)'" and 1000 similar errors. I gues its because qt is not recognizing the JX libraries.
Thanks in advance.
#include "mainwindow.h"
#include <QApplication>
#include "jx.h"
#if defined(_MSC_VER)
// Sleep time for Windows is 1 ms while it's 1 ns for POSIX
// Beware using this for your app. This is just to give a
// basic idea on usage
#include <windows.h>
#else
#include <unistd.h>
#define Sleep(x) usleep(x)
#endif
void callback(JXValue *results, int argc) {
// do nothing
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
const char *contents =
"process.requireGlobal = require;";
JX_Initialize(argv[0], callback);
JX_InitializeNewEngine();
JX_DefineMainFile(contents);
JX_StartEngine();
JXValue ret_val;
JX_Evaluate("process.requireGlobal('./dummy.js').data",
"eval",&ret_val);
while (JX_LoopOnce() != 0) usleep(1);
JX_Free(&ret_val);
JX_StopEngine();
return a.exec();
}
Yes, the 'undefined reference to' is a linker error.
This is due to the fact that the linker can't find the library (libraries) in the paths it already has, so you need to specified it (them) and you've to do it in the .pro file of your Qt project.
.pro file works similarly to makefile: here you have to specify "extra" paths where source and header files are located, as well as libraries.
For your specific question, you need to add all the library requesting to make jxcore working, adding them to the keyword "LIBS": -L introduce path(s) at which libraries are stored, while -l introduce libraries themselves you want to use. I.e.
LIBS += -L/path/to/your/libraries \
-lname_of_library_without_lib
You can find more detailed description at this link http://doc.qt.io/qt-4.8/qmake-project-files.html
Go directly to last section if you're just interested in how add libraries
Hope it helps

Error accessing GStreamer Library in Qt C++ - Program excited with code 0xc0000135 when Debugging

I want to use gstreamer library for video programming and I read that Qt5.5.0 provided support for gstreamer-1.0, which is the library I use. I downloaded firstly version 1.0.7, but I got the following error, so I downloaded the latest version 1.5.2, which I am trying to use now.
I managed to link the gstreamer library header files, so I didn't build it, but just include its path and access the header files and libs. Anyway, now I have an error of The program has unexpectedly finished. When I try to debug it, I get the following error in a pop-up:
During startup program excited with code 0xc0000135.
On General Messages:
:1:24: Reading only version 1.1 parts.
:10:5: Expected only Component and ModuleApi object definitions.
I read many questions related to this error, but none helped, I think is an error with the gstreamer library, but may be a compiler/debugger error too, as I read in some threads.
I checked my PATH variable, as I also can not run the program outside Qt (by trying to run the .exe in debug folder of the build) - the error : library Qt5Cored.dll missing - and I found this paths:
C:\Qt\Qt5.5.0_Android\5.5\mingw492_32\lib;
C:\Users\user\Documents\build-GStreamer-test5-Desktop_Qt_5_5_0_MinGW_32bit-Debug;
C:\Qt\Qt5.5.0_Android\5.5\mingw492_32\bin;
C:\Qt\Qt5.5.0_Android\Tools\mingw492_32\bin;
C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0;
C:\Program Files\Skype\Phone\ (I dont know why is this included, but it was there when I checked )
I am relatively new to Qt, and never encountered this error before. If you need any code:
.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = GStreamer-test5
TEMPLATE = app
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:/gstreamer/1.0/x86/include/gstreamer-1.0
C:/gstreamer/1.0/x86/lib/gstreamer-1.0/include
C:/gstreamer/1.0/x86/include/glib-2.0
C:/gstreamer/1.0/x86/lib/glib-2.0/include
LIBS += -L C:/gstreamer/1.0/x86/lib/ -lgstreamer-1.0
and .main:
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <stdio.h>
#include "gst/gst.h"
void *__gxx_personality_v0;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
const gchar *nano_str;
guint major, minor, micro, nano;
gst_init (&argc, &argv);
gst_version (&major, &minor, &micro, &nano);
if (nano == 1)
nano_str = "(CVS)";
else if (nano == 2)
nano_str = "(Prerelease)";
else
nano_str = "";
// printf ("This program is linked against GStreamer %d.%d.%d %s\n", major, minor, micro, nano_str);
qDebug() << "This program is linked against GStreamer %d.%d.%d %s\n", major, minor, micro, nano_str ;
return a.exec();
Firstly, I had the error :
undefined reference to `__gxx_personality_v0' , but fixed it by adding *void __gxx_personality_v0; , although I don't know what excatly it is.
Its been three days I struggle with this problem. Any help appreciated, or maybe if you can help me by some code on how to access the header files and libs, or how the configuration of the debugger options / PATH must be.
I am using Qt5.5.0 for Android, for Windows I use MinGW 4.9.2 32 bit compiler and GNU gdb 7.8 as debugger.
Thanks in advance!
I had similar problems in my project that was using both Qt and Gstreamer.
The сause of "undefined reference to `__gxx_personality_v0'" error is that Qt and GStreamer for windows from official sites were built using different compilers and their libstdc++ libraries are not compatible - they are using different exception handling methods.
In fact, GStreamer is pure C library. The only component of it that was written in C++ is taglib library. If you will build this lib from sources using your MinGW compiler, and then replace it in the GStreamer folder, the problem of incompatibility will be solved.
In more detail you can read here: https://github.com/knowthelist/knowthelist.
I managed to solve the above problem. I had to include in the .exe folder (the build-debug folder) all the dlls included, so I tried to run the .exe from there, not run it from Qt, and some errors with dlls missing gave me the names of the dlls. I found some in my library bin folder and some downloaded, and now everything seems fine :)

Basic Open GL/GLUT Issue

I am studying graphics and currently using OpenGL with GLUT. Doing my editing in codeblocks and using an online tutorial located at lighthouse3d. I am using the main method declared on that page however it will not let me compile. The error message consists of the main method not returning an int, I have "played" with the code enough to say I am confused. The GLUT Library is installed, and I do not see where the error is coming from.
Thank you,
Zach Smith
You probably have a method like this:
void main(int argc, char** argv) {
// The code...
}
Change it to this:
int main(int argc, char** argv) {
// The code...
return 0;
}
The problem is that you are not linking the needed libraries.
Go to the project properties by right clicking on the project icon in the 'Solution Explorer' and click on 'Properties'. Then go under 'Configuration Properties' -> 'Linker' -> 'Input' and add the following libraries to the 'Additional Dependencies' field:
opengl32.lib glut32.lib glu32.lib
Rebuild your project and all should be fine!