I have installed the last QT Creator, running a gived example code, but i get
error: 'QGLFormat' file not found and
error: 'QGLWidget' file not found
My pro file looks like
GLEW_PATH = ../ext/glew-1.9.0
GLM_PATH = ../ext/glm-0.9.4.1
TEMPLATE = app
TARGET = myfilename
LIBS += -Wl,-rpath $${GLEW_PATH}/lib -L$${GLEW_PATH}/lib
LIBS += -lGLEW -lGL -lGLU -lm
INCLUDEPATH += $${GLEW_PATH}/include $${GLM_PATH}
SOURCES = main.cpp viewer.cpp
HEADERS = viewer.h
CONFIG += qt opengl warn_on thread uic4 release
QT += core gui opengl xml widgets
The errors happen here in my only header viewer.h, but others includes look fine
// GLEW lib: needs to be included first!!
#include <GL/glew.h>
// OpenGL library
#include <GL/gl.h>
// OpenGL Utility library
#include <GL/glu.h>
// OpenGL Mathematics
#include <glm/glm.hpp>
#include <QGLFormat> //Error here
#include <QGLWidget> //and here
#include <QMouseEvent>
#include <QKeyEvent>
...
with a main quite simple
#include <qapplication.h>
#include <QString>
#include "viewer.h"
int main(int argc,char** argv) {
QApplication application(argc,argv);
Viewer viewer;
viewer.show();
return application.exec();
}
Related
I develop a generic interface library with qt. I have trouble with pressed effect on QPushbutton when I click with a touch screen (this effect appears one time on 10 click).
So I create a basic qml application with one button and pressed effect appear all time. I incude the qml part into my library and load it in QQuickWidget and I have same problem with pressed effect.
So I want to use only qml. My principal application is a QApplication and I load my library in it in which I load qml file with QQmlApplication Engine. Then I show it by QQuickWindow.
When I launch my application I saw the window open but it is automatically close. I think my QApplication don't detect QML and the renderer loop is not start.
I'm on windows with QT5.5.1 (MSVC2013, 32bit)
pro file of main application
QT += core xml widgets qml quick
TARGET = COM_INT
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
comint.cpp
HEADERS += \
comint.h \
INCLUDEPATH += "$$(My_Workspace)/Modules_Generique/IHM_Soft"
Release{
LIBS += "$$(My_Workspace_build)/IHM_Soft/release/IHM_Soft.lib"
}
Debug{
LIBS += "$$(My_Workspace_build)/IHM_Soft/debug/IHM_Soft.lib"
}
Main application (exe) main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
#include "comint.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ComInt com;
com.initialize();
return a.exec();
}
ComInt class:
Source file comint.cpp
#include "comint.h"
#include "ihmsoft.h"
ComInt::ComInt()
{
}
void ComInt::initialize()
{
this->m_pIHMSoft = new IHMSoft();
}
header file comint.h
#ifndef COMINT_H
#define COMINT_H
class IHMSoft;
class ComInt
{
public:
ComInt();
void initialize();
private:
IHMSoft *m_pIHMSoft;
};
#endif // COMINT_H
pro file of shared lib
QT += xml widgets core qml quick quickwidgets
CONFIG += c++11
TARGET = IHM_Soft
TEMPLATE = lib
DEFINES += IHM_SOFT_LIBRARY
SOURCES += ihmsoft.cpp
HEADERS += ihmsoft.h\
ihm_soft_global.h
RESOURCES += \
rsc.qrc
Shared library: source file ihm_soft.cpp
#include "ihmsoft.h"
#include <QQmlApplicationEngine>
#include <QQuickWindow>
IHMSoft::IHMSoft(){
qputenv("QT_QUICK_CONTROLS_STYLE", "Base");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/IHM_Soft.qml")));
QList<QObject*> root = engine.rootObjects();
QQuickWindow *window = qobject_cast<QQuickWindow*>(root.at(0));
window->show();
}
header file ihm_soft.h
#ifndef IHM_SOFT_H
#define IHM_SOFT_H
#include "ihm_soft_global.h"
class IHM_SOFT_SHARED_EXPORT IHM_Soft
{
public:
IHM_Soft();
};
#endif // IHM_SOFT_H
Global file ihm_soft_global.h
#ifndef IHM_SOFT_GLOBAL_H
#define IHM_SOFT_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(IHM_SOFT_LIBRARY)
# define IHM_SOFT_SHARED_EXPORT Q_DECL_EXPORT
#else
# define IHM_SOFT_SHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // IHM_SOFT_GLOBAL_H
Qml file
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Window 2.0
ApplicationWindow {
visible: true
width: 500
height: 500
Button {
visible: true
iconSource: "resources/t_on_off.png"
}
}
Edit: Sorry the code of the main application was a test application which do not include lib.
A variable is deleted when its scope ends, in your case engine is a local variable that is deleted when IHMSoft finishes being built, so you see that the window closes. The solution is to make it a member of the class:
*.h
#ifndef IHM_SOFT_H
#define IHM_SOFT_H
#include "ihm_soft_global.h"
#include <QQmlApplicationEngine>
class IHM_SOFT_SHARED_EXPORT IHM_Soft
{
public:
IHM_Soft();
private:
QQmlApplicationEngine engine; // member
};
#endif // IHM_SOFT_H
*.cpp
#include "ihmsoft.h"
IHMSoft::IHMSoft(){
qputenv("QT_QUICK_CONTROLS_STYLE", "Base");
engine.load(QUrl(QStringLiteral("qrc:/IHM_Soft.qml")));
}
Recently build OPENCV 3.4.3 with CMAKE 3.12.4 and MINGW64(32bit) 8.1.0 in Windows 7. Have QT 5.6 and i trying to test this build as QT Console App, but when i compiling with QT only get the message "Press "RETURN" to close this window...".
.PRO file:
CONFIG += c++11
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
OTHER_FILES += test.png
INCLUDEPATH += C:\Users\Test\Desktop\opencv\build\include
LIBS += C:\Users\Test\Desktop\mingw\bin\libopencv_*.dll
main.cpp:
#include <QCoreApplication>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
using namespace std;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
cout << "Hello World!" << endl;
cv::Mat mat;
mat = cv::imread("test.png");
cvNamedWindow("hello");
cv::imshow("hello",mat);
return a.exec();
}
What im doing wrong?
Imo the problem is not in your code, I just run it (using Qt5.5, Win10, openCV 4 and mingw64), even if I had to change cvNamedWindow to cv::namedWindow.
I have two hints:
did you build openCV with mingw64? If not, do so.
are the openCV dlls in the path when you run the application? You can also copy all opencv dlls in the program folder to check that quickly...
I'm a beginner in working with CGAL libraries , I tried to run a combinatorial map example qt-creator on fedora after combiling CGAL:
#include <QCoreApplication>
#include <CGAL/Combinatorial_map.h>
#include <iostream>
#include <cstdlib>
typedef CGAL::Combinatorial_map<3> CMap_3;
typedef CMap_3::Dart_const_handle Dart_const_handle;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
CMap_3 cm;
// Create two tetrahedra.
Dart_const_handle dh1 = cm.make_combinatorial_tetrahedron();
Dart_const_handle dh2 = cm.make_combinatorial_tetrahedron();
// Display the combinatorial map characteristics.
cm.display_characteristics(std::cout);
std::cout<<", valid="<<cm.is_valid()<<std::endl;
unsigned int res = 0;
// Iterate over all the darts of the first tetrahedron.
// Note that CMap_3::Dart_of_orbit_range<1,2> in 3D is equivalent to
// CMap_3::Dart_of_cell_range<3>.
for (CMap_3::Dart_of_orbit_range<1,2>::const_iterator
it(cm.darts_of_orbit<1,2>(dh1).begin()),
itend(cm.darts_of_orbit<1,2>(dh1).end()); it!=itend; ++it)
++res;
std::cout<<"Number of darts of the first tetrahedron: "<<res<<std::endl;
res = 0;
// Iterate over all the darts of the facet containing dh2.
for (CMap_3::Dart_of_orbit_range<1>::const_iterator
it(cm.darts_of_orbit<1>(dh2).begin()),
itend(cm.darts_of_orbit<1>(dh2).end()); it!=itend; ++it)
++res;
std::cout<<"Number of darts of the facet containing dh2: "<<res<<std::endl;
return a.exec();
}
.pro file:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp
INCLUDEPATH += /usr/include
LIBS += -lgmp -lmpfr -lCGAL
but it shows the following error:
In file included from /usr/include/c++/7/bits/stl_algo.h:59:0,
from /usr/include/c++/7/algorithm:62,
from /usr/include/QtCore/qglobal.h:68,
from /usr/include/qt5/QtCore/qcoreapplication.h:43,
from /usr/include/qt5/QtCore/QCoreApplication:1,
from ../untitled/main.cpp:1:
/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
I searched about the problem , but nothing is working with me
I appreciate any help
thanks
I solved it by removing INCLUDEPATH += /usr/include from .pro file
I got an solution: replace all #include_next with #include.
My goal is to run a simple OpenCV contribute (extra) module in Qt 5.5.1.
Steps:
1) created a Qt Application app;
2) changed the main.cpp file to :
#include <QApplication>
#include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>
#include <QDebug>
using namespace std;
using namespace cv;
int main(int argc, char*argv[])
{
qDebug() <<"start!" << endl;
QApplication a(argc, argv);
string trackingAlg = "KCF";
MultiTracker trackers(trackingAlg);
qDebug() <<"success!" << endl;
return a.exec();
}
and here is my .pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = tracker4
CONFIG += c++11
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
LIBS += `pkg-config opencv --libs`
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_videoio -lopencv_tracking
The program compiles successfully, but in the runtime, it crashes without even running the main() function. I don't get such an error when I run this in Code::Blocks but in Qt I still have this issue.
I am using Qt 5.5.1 and Ubuntu 14.04.
Can anyone generate this "seg fault" error in his/her machine?
For QT 5, build the OpenCV with QT=OFF.
For QT 4, build the OpenCV with QT=ON.
I'm trying to get the following c++ program using Qwt v. 6.0.1 to work:
#include <cmath>
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QwtPlot plot(QwtText("CppQwtExample1"));
plot.setGeometry(0,0,640,400);
plot.setAxisScale(QwtPlot::xBottom, 0.0, 2.0*M_PI);
plot.setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
QwtPlotCurve sine("Sine");
std::vector<double> xs;
std::vector<double> ys;
for (double x=0; x<2.0*M_PI; x+=(M_PI/10.0)) {
xs.push_back(x);
ys.push_back(std::sin(x));
}
sine.setData(&xs[0], &ys[0], xs.size());
sine.attach(&plot);
plot.show();
return a.exec();
}
and the .pro file looks like:
TEMPLATE = app
TARGET = CppQwtExample1
QMAKEFEATURES += /usr/local/qwt-6.0.1/features
CONFIG += qwt
INCLUDEPATH += /usr/local/qwt-6.0.1/lib/qwt.framework/Headers
LIBS += -L/usr/local/qwt-6.0.1/lib/qwt.framework/Versions/6/ \
-lqwt
SOURCES += qwtTest.cpp
However, when I now try to do
qmake
make
I get the error:
ld: library not found for -lqwt
collect2: ld returned 1 exit status
make: * [qwtTest.app/Contents/MacOS/qwtTest] Error 1
I surely miss something here. Any help is greatly appreciated.
LIBS += -L/usr/local/qwt-6.0.1/lib/qwt.framework/Versions/6/ -lqwt
This is wrong. Due to the naming conventions of Mac OS X frameworks, the dynamic library inside qwt.framework isn't named "libqwt.dylib" (which the linker requires), but simply "qwt".
Use
LIBS += -F/usr/local/qwt-6.0.1/lib -framework qwt
instead.