make 64 bit com control with qt - c++

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);
..............

Related

Accessing Qt GUI ui from another class OR using connect() to update gui elements

I need some help understanding how to access the QT GUI ui from another class/another cpp file.
Background: I am working on a project that consists of many cpp and hpp files. I am not the original author. This project is to control a USRP to receive/send data....with various parameters. Originally, you had to manually change parameter values inside several cpp files (i..e start frequency, steps, duration of receive, etc). Then re-compile and then run the executable. I wrote a simple Qt GUI interface in the main.cpp function where the users would enter in the GUI basic usrp receive parameters. Then the GUI interface would pass these values back into the uspr function that would actually execute the USRP functionality. This part is actually working great and I am happy (my first GUI!, Yay!)
One thing that I would like to do is to also display the current frequency in the main GUI window via the LCDNumber widget. This frequency is managed by another class, in another cpp file.
Here is what I tried:
Attempt #1: Make the MainWindow ui publicly available int the class/cpp file where the Frequency is established:
freq_transmit.cpp:
......
#include "mainwindow.hpp"
#include "ui_mainwindow.hpp"
.....
void Receiver::run()
{
//bunch of lines of code about USRP stuff
.....
rxCenterFreq // <---variable that holds the current frequency (which changes every second)
ui->lcdnumber->display(rxCenterFreq); // <-- -compiler error: ui not declared in this scope
............
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtCore>
#include <QCoreApplication>
#include <QPalette>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
Ui::MainWindow *ui;
QPalette temp_red;
QPalette temp_green;
private slots:
void on_button_CalcSchedule_clicked();
void on_button_Reset_clicked();
void execute_run_usrp();
void on_button_QUIT_clicked();
void on_AutoSchedulerCheckBox_stateChanged(int arg1);
void on_button_manul_CalcSchedule_clicked();
void on_button_EXECUTE_clicked();
void on_button_SeeSchedule_clicked();
void on_button_STOP_clicked();
void function_test();
public slots:
void updateTXFreq(double a);
private:
void reset_sweep_values();
std::string calc_schedule_start_time(int minute_cadence);
void calc_cadence();
double calc_sweep_duration();
int nearest_cadence(int numToRound, int multiple);
signals:
void send_start_schedule(std::string, double, int, int);
};
#endif // MAINWINDOW_H
Attempt #2: Use Qt CONNECT functionality:
Step 1: generate a SIGNAL / emit function in the freq_transmit.hpp header:
....
signals:
void sendTXFreq(double a);
Step 2: Enter this emit signal in the freq_transmit.cpp file where the Frequency is being generated:
freq_transmit.cpp:
......
#include "mainwindow.hpp"
#include "ui_mainwindow.hpp"
.....
void Receiver::run()
{
//bunch of lines of code about USRP stuff
.....
emit sendTXFreq(rxCenterFreq); // emit signal to QT
....
Step 3: Declare a SLOT in mainwindow.h to accept emitted signal
mainwindow.hpp:
...
public slots:
void updateTXFreq(double a);
Step 4: Implementation:
mainwindow.cpp:
....
void MainWindow::updateTXFreq(double a)
{
ui->lcdnumber->display(a);
}
connect(&Receiver, &Receiver::sendTXFreq, this, &MainWindow::updateTXFreq); // <-- error: expected primary expression before ','
which is the comma after "&Receiver", which is a class that has various functions in it, including the Receiver::run() where Frequency is generated.`
Long story short, I am trying to have the generated frequency linked to a LCDNumber widget so that it shows on the GUI the value of frequency as the USRP code runs.
PS: I am not an expert C++ coder, I am just now learning about classes and QT GUI. Somebody mentioned that I should "create a pointer of my MainWindow in the freq_transmit.cpp file" so that then I can accesss ui elements direclty in that class, but I thought I tried that with ui->lcdnumber->display(rxCenterFreq);
Any guidance much appreciated and thank you!

Using glad in Qt: QOpenGL and glad are conflicting

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!

cannot inherit from web page class without runtime error

I have a Qt(QObject) class that, when declared, crash the application either right after initilization or few seconds after GUI show up.
The class is exactly this:
webPage.h
class webPage : public QWebPage
{
Q_OBJECT
public:
webPage(QObject *parent = 0);
~webPage();
};
webPage.cpp
webPage::webPage(QObject *parent)
: QWebPage(parent)
{
qDebug() << "webPage::webPage() got called!";
}
webPage::~webPage()
{
}
And my mainwindow.h class:
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void closeEvent(QCloseEvent *e);
private slots:
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
public:
Ui::MainWindow *ui;
browserControl webControl;
webPage page; // <-- unless I remove this, the application crashs.
};
The constructor is like this:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//webControl.setPage(&page);
}
Can someone help me to point out the error reason? it isn't even SEGFAULT or something, start in debug mode doesn't helps, the application crashs/frooze.
Exactly from webkitwidgets documentation:
Building the Qt WebKit module with debugging symbols is problematic on many platforms due to the size of the WebKit engine. We recommend building the module only in release mode for embedded platforms. Currently Qt WebKit will always be compiled without debugging symbols when using gcc. Take a look at Tools/mkspecs/features/production_build.prf if you need to change this.
As corresponded in this BUG QTBUG-44108 ... Qt WebEngine is only available in the MSVS 2013 packages on Windows. MinGW and previous Visual Studio versions do not work at the moment, so you'll need Visual Studio 2013 or Visual Studio 2013 Express Edition
Also, some experienced recommend doing Porting from Qt WebKit to Qt WebEngine

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.

ISO C++ forbids declaration of 'QPushButton' with no type in QT Creator

I am running QT Creator on a Linux Ubuntu 9.10 machine. I just got started with QT Creator, and I was going through the tutorials when this error popped up while I was trying to build my project: "ISO C++ forbids declaration of 'QPushButton' with no type". This problem appears in my header file:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QWidget>
namespace Ui
{
class MainWindow;
}
class MainWindow : public QWidget
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void addContact();
void submitContact();
void cancel();
private:
Ui::MainWindow *ui;
QPushButton *addButton;
QPushButton *submitButton;
QPushButton *cancelButton;
QLineEdit *nameLine;
QTextEdit *addressText;
QMap<QString, QString> contacts;
QString oldName;
QString oldAddress;
};
#endif // MAINWINDOW_H
I think you are simply missing the appropriate header file. Can you try
#include <QtGui/QtGui>
instead, or if you prefer
#include <QtGui/QPushButton>
Actually, forward declaration would be enough, instead of the include:
class QPushButton;
Always prefer forward declarations in headers, and do the include in the .cpp
(faster and less recompilations in larger projects).
You are missing this:
#include <QtGui>
You might also want to check the .pro file.
Do you have an entry like "QT = ..." somewhere? If so, try changing that to "QT += ...". Qt's Core and GUI module are default settings for the QT variable, but CAN be overwritten, which will lead to compiler and/or linker errors.