QT - how to fix link error 2019 with qt VS tools - c++

I'm trying to create a simple qt application in visual studio, I also made sure to install all qt components.
Code:
#include "QtWidgetsApplication2.h"
#include <QtWidgets/QApplication>
#include <QtDataVisualization/Q3DSurface>
#include <QtDataVisualization/QSurfaceDataProxy>
#include <QtDataVisualization/QHeightMapSurfaceDataProxy>
#include <QtDataVisualization/QSurface3DSeries>
#include <QtWidgets/QSlider>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtWidgetsApplication2 w;
Q3DSurface* graph = new Q3DSurface();
QWidget* container = QWidget::createWindowContainer(graph);
w.show();
return a.exec();
}
I have already set the correct QT version, and the path to the aditional libraries for the linker(at C:\Qt\6.4.0\msvc2019_64\lib) but somehow i'm still getting an error linker LNK2019. What gives?
EDIT:
my .pro file:
TEMPLATE = app
TARGET = QtWidgetsApplication2
DESTDIR = ../x64/Debug
CONFIG += debug
DEPENDPATH += .
MOC_DIR += .
OBJECTS_DIR += debug
UI_DIR += .
RCC_DIR += .
include(QtWidgetsApplication2.pri)

From the Qt documentation for Q3DSurface here: https://doc.qt.io/qt-6/q3dsurface.html on the qmake line at the top it has qmake: QT += datavisualization the QT += datavisualization part is what you need to add to your .pro file to use the Q3DSurface class. This will setup the linking and any additional include directories.

Related

How to compile a Qt program without qtCreator on Windows?

I have read the question Can I use Qt without qmake or Qt Creator? which is basically the same for Linux, and very useful.
How to compile a basic program using QtCore (console application, even without GUI) on Windows, without using qmake or qtCreator IDE, but just the Microsoft VC++ compiler cl.exe?
For example, let's say we have:
#include <iostream>
#include <QtCore>
int main()
{
QVector<int> a; // Qt object
for (int i=0; i<10; i++)
a.append(i);
std::cout << "hello";
return 0;
}
Using:
call "C:\path\to\vcvarsall.bat" x64
cl main.cpp /I D:\coding\qt\qtbase-everywhere-src-5.15.5\include
fails with:
D:\coding\qt\qtbase-everywhere-src-5.15.5\include\QtCore\QtCore(3): fatal error C1083: Cannot open include file: 'QtCore/QtCoreDepends': No such file or directory
Indeed this file is not present in the release qtbase-everywhere-opensource-src-5.15.5.zip from https://download.qt.io/archive/qt/5.15/5.15.4/submodules/.
TL;DR: More generally, which cl.exe arguments should we use to to able to use all Qt includes, and effectively compile such a minimal project using QtCore?
I finally managed to do it 100% from command line, without the qtCreator IDE, but not yet without qmake. Steps to reproduce:
Let's assume Microsoft MSVC 2019 is installed.
Install qt-opensource-windows-x86-5.14.2.exe. (This is the latest Windows offline installer I could find), double check that you install at least msvc2017_64.
Note: Don't use qtbase-everywhere-opensource-src-5.15.4.zip: using the include subfolder from this package for cl.exe /I ... is not enough. (I thought it would, at first)
Create a folder example containing the main.cpp file above
Open a command line window in this folder and do:
vcvarsall.bat x64
Now either do "c:\path\to\msvc2017_64\bin\qmake.exe" -project to create a example.pro project file or create it manually with:
TEMPLATE = app
TARGET = qt_example
INCLUDEPATH += .
CONFIG += console
SOURCES += main.cpp
Do "c:\path\to\msvc2017_64\bin\qmake.exe". This will create a Makefile file.
Run nmake. This is Microsoft MSVC's equivalent of the make tool.
Copy c:\path\to\msvc2017_64\bin\Qt5Core.dll into the release folder
Run release\example.exe. Working!
Addendum: here is solution now for a minimal GUI app:
main.cpp
#include <QtCore/QCoreApplication>
#include <QTextStream>
#include <QMessageBox>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMessageBox::information(NULL, "Hello", "Hello", "Ok");
return a.exec();
}
qt_example_gui.pro
TEMPLATE = app
TARGET = qt_example_gui
INCLUDEPATH += .
SOURCES += main.cpp
QT += gui widgets
Do the vcvarsall.bat x64, qmake, nmake like in the solution above. No be sure you have this file structure:
release\qt_example_gui.exe
release\Qt5Core.dll
release\Qt5Gui.dll
release\Qt5Widgets.dll
release\platforms\qwindows.dll
Run the .exe, that's it!

Simple Qt project with openCV instantly crash

I try to use openCV in a Qt project. But my release build instantly crash on launch if I link the release libs of openCV. Debug libs allow the programm to start but the application crashes when I try to use openCV functions (it is known that mixing release/debug in openCV causes some crash).
So I made a simple project and it won't even launch. Both release and debug build crashes and using debugger causes a small window saying 'unexpected CDB exit'.
Here are the source.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test_openCV
TEMPLATE = app
#flags to generate a .map file
QMAKE_LFLAGS_RELEASE +=/MAP
QMAKE_LFLAGS_RELEASE += /debug
SOURCES += main.cpp\
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
INCLUDEPATH += $$PWD
INCLUDEPATH += "D:/openCV/build/include"
#Switching between handbuild and the build I downloaded have no effect.
#I am sure the path are good. Quadra checked.
#LIBS += -L"D:/openCV/build/x64/vc11/lib"
LIBS += -L"D:/openCV/hand_build/lib/Release"
LIBS += -L"D:/openCV/hand_build/lib/Debug"
#disables the "fopen not secure" warning in openCV.
DEFINES += _CRT_SECURE_NO_WARNINGS
win32:CONFIG(release, debug|release): LIBS += -lopencv_core2413 -lopencv_highgui2413 -lopencv_imgproc2413
else:win32:CONFIG(debug, debug|release): LIBS += -lopencv_core2413d -lopencv_highgui2413d -lopencv_imgproc2413d
main.cpp:
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
MainWindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <opencv/cv.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
and MainWindow.cpp:
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Removing this line will causes the program to start normally (guess it won't link the libs if nothing from openCV is used).
cv::Mat image;
}
MainWindow::~MainWindow()
{
delete ui;
}
What I get when launching app:
Starting D:\Colin\build_test_openCV\release\test_openCV.exe...
program suddenly ended
D:\Colin\build_test_openCV\release\test_openCV.exe crashed
I work on Windows 7 / MSCV2012 openGL 64bits / Qt 5.2.1 openGL.
Does anyone see a mistakes I could have made?
I have a similar setup as yours and was getting the exact same problem. The issue was that the path to the corresponding dlls was not defined. These dlls:
opencv_core2411.dll
opencv_highgui2411.dll
opencv_imgproc2411.dll
should be in D:/openCV/hand_build/bin/ (or maybe D:/openCV/hand_build/bin/Release/). Adding another line:
LIBS += -L"D:/openCV/hand_build/bin/Release/"
should work.
I just had a similar issue. The program was crashing because it could not find the appropriate DLL at runtime. Adding the OpenCV directories to my Windows PATH fixed the problem for me.
All items in your build must have been built using the same Visual Studio version, that means:
The Qt install you're using.
OpenCV.
Your code.
Most likely at least one of the above was not built using the same compiler. If OpenCV is linked against Qt, it must have been built against a binary-compatible version of Qt, too.

Cannot #include <QWebView> using QtCreator

I have read a lot trying to figure this out. I am using QtCreator on Ubuntu 13.10.
.pro:
#-------------------------------------------------
#
# Project created by QtCreator 2014-03-02T09:50:03
#
#-------------------------------------------------
QT += core gui
QT += webkit
QT += webkit webkitwidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = AndroidDecompiler
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
MAIN
#include "mainwindow.h"
#include <QApplication>
#include <QtWebKit>
#include <QWebView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
QWebView view;
view.show();
view.setUrl(QUrl("http://google.com"));
return a.exec();
}
Here is error ':-1: error: cannot find -lsqlite3'
I think it is due to not being able to include webview. Is their any suggestions?
You could install the sqlite3 library as follows:
sudo apt-get install sqlite3 libsqlite3-dev
I think you can replace the header:
#include <QtWebKit>
#include <QWebView>
with:
#include <Qt/QtGui>

Qt5 Compiler Error: 'QtQuick': No such file or directory

I created a Qt-GUI-Application, in which I want to embed a QtQuick 2.0 QML file.
For that matter I added QT += quick in the .pro file
this is what my code looks like:
#include <QApplication>
#include <QtCore>
#include <QtQuick>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QQuickViewviewer;
viewer.setSource(QUrl::fromLocalFile("file.qml"));
viewer.show();
return a.exec();
}
But all I get is the following error message as soon as I want to built it:
..\main.cpp:3: Error:C1083: Cannot open include file: 'QtQuick': No such file or directory
How can I solve this?
I'm using Qt 5.1.1 on Windows 7
Edit:
This is how the .pro file looks like
#-------------------------------------------------
#
# Project created by QtCreator 2013-10-15T17:54:42
#
#-------------------------------------------------
QT += core gui \
quick
TARGET = IntegratedPowerSupply
TEMPLATE = app
SOURCES += main.cpp
HEADERS +=
OTHER_FILES += \
../../PowerSupply/PowerSupply/file.qml

QT5 Migration Cannot open include file: 'QGraphicsWebView'?

Simple code:
#include <QCoreApplication>
#include <QGraphicsWebView>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}
Sample .pro:
QT += core gui declarative network webkit multimedia
TARGET = QTTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
And error I get:
C1083: Cannot open include file: 'QGraphicsWebView': No such file or directory
What the is going on there in QT5? this class shall Be included like this and so I shall see no such error? I do not get some fancy QT5 new feature?
In the line
QT += core gui declarative network webkit multimedia
replace webkit by webkitwidgets :
QT += core gui declarative network webkitwidgets multimedia