Using glad in Qt: QOpenGL and glad are conflicting - c++

QT version: 5.12.0
OpenGL version: 4.5 core
Development environment: VS 2017
pro file:
QT += widgets
...
I have already add the glad.c file into my project, and ensure that the glad.h is included at the first place in every file.
But while I compile my project, all the other classes that using OpenGL functions are normal, except the class inherited from QOpenGLWidget.
MappingView.h
#include <glad/glad.h>
...
class MappingView : public QOpenGLWidget {
Q_OBJECT
public:
MappingView(QWidget * parent = nullptr);
~MappingView();
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
...
GLuint m_pointer_texture;
}
MappingView.cpp
MappingView::MappingView(QWidget * parent) : QOpenGLWidget(parent) {
}
MappingView::~MappingView() {
glDeleteTextures(1, &m_pointer_texture);
}
void MappingView::initializeGL() {
// load glad
if (!gladLoadGL()) {
return;
}
glGenTextures(1, &m_pointer_texture);
}
Compile error: C3861, cann't find glDeleteTextures.
When I click to the definition of glDeleteTextures in VS, it will jump to QOpenGLFunctions, but not glad.h. It seems that the OpenGL in QT and glad is conflicting. But my project doesn't use QOpenGLFunctions.
When I try to add a macro in MappingView.h,
#define QT_NO_OPENGL
all OpenGL functions in MappingView can be successfully found in glad.h, but the base class QOpenGLWidget cannot be found instead, which means that the MappingView class cannot be inherited from QOpenGLWidget any more.
I would be very appreciated if somebody could help me to resolve the problem, thanks!

Related

How to add C++ QQuickPaintedItem in QML

I want to add C++ class like this notchedrectangle.hpp to QML:
#ifndef NOTCHEDRECTANGLE_HPP
#define NOTCHEDRECTANGLE_HPP
#include <QtQml/qqmlregistration.h>
#include <QQuickPaintedItem>
class NotchedRectangle : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
QML_ELEMENT
public:
NotchedRectangle();
void paint(QPainter* painter) override;
QColor color() const;
void setColor(QColor color);
signals:
void colorChanged();
private:
QColor m_color;
};
#endif // NOTCHEDRECTANGLE_HPP
I have qmake build system, but don't know - what should I add in qmake file.
My filesystem looks like that:
I tried to add to qmake file this strings:
CONFIG += qmltypes
QML_IMPORT_NAME = UI.NR
QML_IMPORT_MAJOR_VERSION = 1
INCLUDEPATH += UI/NotchedRectangle
But they will cause error:
[Makefile.Debug:1175: qlauncher_metatypes.json] Error 1
Can you help me, please?
you should import in qml file after exposing the class:
import UI.NR 1.0
I suggest you to change UI.NR to smth else which has no dot in it.
Then take an instance:
WhatEverYouNamed {
}
QML_IMPORT_NAME is not a name of class!
It's the name of package and must be different.
I use "Custom".
Next you must include class in main.cpp
And finally - you should make Recompile

make 64 bit com control with qt

I want to make ActiveX from my current source code that have been written in Qt framework and add it to visual studio as a COM control and use it in C#. I have done it with Qt 4.8.6 and Visual Studio 2010 and it worked. However when I change target machine to 64 bit in visual studio, it no longer works. I came across that it compile with a 32 bit dll and I have to compile it with 64 bit dll after that I compile Qt 4.8.6 for VS 2012 64 bit and I compiled it with 64 bit dll successfully and I register it - it registers successfully but when I try to add it as COM control it gives me this error:
Self registration for D:..... .dll faild.
how can I fix this problem?I compile it with qt 5.0.1 and it was the same.
#ifndef OBJECTS_H
#define OBJECTS_H
#include <QWidget>
#include <QColor>
QT_BEGIN_NAMESPACE
class QVBoxLayout;
QT_END_NAMESPACE
class QSubWidget;
class CirclesGraphicsScene;
class CirclesGraphicsView;
//! [0]
class Circles : public QWidget
{
Q_OBJECT
Q_CLASSINFO("ClassID", "{d574a747-8016-46db-a07c-b2b4854ee75c}")
Q_CLASSINFO("InterfaceID", "{4a30719d-d9c2-4659-9d16-67378209f822}")
Q_CLASSINFO("EventsID", "{4a30719d-d9c2-4659-9d16-67378209f823}")
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
Q_PROPERTY(int circleNumber READ circleNumber WRITE setCircleNumber)
void createScene();
public:
Circles(QWidget *parent = 0);
QSize sizeHint() const;
QColor backgroundColor()const;
int circleNumber()const{return _n;}
public slots:
//--general
void setBackgroundColor(QColor color);
void setCircleNumber(int n);
//--axes
//void setAxesPen(QColor color, int w , int penStyle);
//--circles
void addCircles(int r, int n, int s, int e);
..............

Why doesn't my Qt Creator know QPolygon?

I have the following simple code. I just start writing my application and get stuck on this problem: Qt Creator tells me, that QPolygon file or directory doesn't exists. I checked it with QT Documentation and it says, ther is.
#include <QPolygon>
class IHledani
{
public:
virtual IHledani();
virtual ~IHledani();
virtual QPolygon najdiKonturu(IObraz image, int startx, int starty);
};
Thank you

Signal_draw in Gtkmm2.4

I'm trying to compile a gtkmm application that uses cairomm for drawing.
It compiles fine using gtkmm3.0 but when I try to compile it using gtkmm2.4 i get:
error: ‘signal_draw’ was not declared in this scope
I'm using g++.
It seems that there is no signal_draw in gtkmm2.4(Am I wrong?). Is there any function/signal that can be used instead?
Thanks in advance.
Sorry for my bad English.
Some code:
class egclass: public Gtk::DrawingArea
{
public:
egclass();
virtual ~egclass();
virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
};
egclass::egclass()
{
#ifndef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
signal_draw().connect(sigc::mem_fun(*this, &egclass::on_draw), false);
#endif
}
The older gtkmm 2.4 has on_expose_event instead:
virtual bool on_expose_event(GdkEventExpose* event);
If you need to create a cairo context for drawing, with the GTK+ C API it goes something like this:
cairo_t *cr;
cr = gdk_cairo_create (event->window);
gdk_cairo_region (cr, event->region);
cairo_clip (cr);
/* do your drawing */
cairo_destroy (cr);
... translating the snippet above to gtkmm is left as an exercise to the reader.
Also see the following links:
Porting from gtkmm-2.4 to gtkmm-3.0
Migrating from GTK+ 2.x to GTK+ 3
example_pixbufs.cc

Undefined reference to vtable, Qt in Linux

I was trying to compile a Qt and OpenGL program under Code::Blocks in Ubuntu 10.04. I get the 'undefined reference to 'vtable for GLWidget'
#ifndef _GLWIDGET_H
#define _GLWIDGET_H
#include <QtOpenGL/QGLWidget>
#include "stdlib.h"
class GLWidget : public QGLWidget {
Q_OBJECT // must include this if you use Qt signals/slots
public:
GLWidget(QWidget *parent = 0);
~GLWidget();
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
void keyPressEvent(QKeyEvent *event);
};
#endif /* _GLWIDGET_H */
I borrowed the code from this guy to see if it works, because mine wasn't working because of the same reason. Code
And here is the GLWidget.cpp:
#include <QtGui/QMouseEvent>
#include "glwidget.h"
GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
setMouseTracking(true);
}
GLWidget::~GLWidget()
{
}
void GLWidget::initializeGL() {
...
}
void GLWidget::resizeGL(int w, int h) {
...
}
void GLWidget::paintGL() {
...
}
void GLWidget::keyPressEvent(QKeyEvent* event) {
...
}
}
I removed the code from the GL part to keep it shorter. Should you need it, I can always post it up.
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include "glwidget.h"
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
GLWidget window;
window.resize(800,600);
window.show();
return app.exec();
}
In your project.pro file add
QT += opengl
So it knows that it has to link to GL libraries.
Clean your project and run qmake on it.
'undefined reference to 'vtable for GLWidget' most probably means that the definition of the first non inline virtual function of GLWidget isn't linked in the executable.
In the present case, my guess it is that it should be provided by the file generated by moc (but as I don't program for QT, I may be mistaken here).
This happens sometimes when adding Q_OBJECT to a header file and can mean a missing moc_ file.
I have found from personal experience doing the following has resolved the issue:
$ qmake filename.pro
$ make
I had this exact problem after adding Q_OBJECT to one of the header files in my project.
I was only getting this error message from within QT Creator, and not when I built my project from the Linux command line.
For me, the solution was to delete the YourProjectName-build-desktop folder which resides on the same level as your project directory. Then when I built the project from within QT Creator, it magically worked.