cannot inherit from web page class without runtime error - c++

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

Related

The question about QMediaPlayer playback MP4 program exits abnormally

When using QMedaiPlayer in QT to play MP4 files, the build passes normally, and the program quits abnormally during runtime, which has troubled me for many days. I hope everyone can help!
There is no problem with the build, and it exits abnormally during runtime.
The replacement of a smaller MP4 file still does not work, so it is not a matter of MP4 file size.
The use of MKV files will not work, nor is it a file format issue.
The version is QT 5.12.8
This is the mainwindow.cpp file
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow){
this->setFixedSize(1024,576);
ui->setupUi(this);
QHBoxLayout *m_layout= new QHBoxLayout(this);
QMediaPlayer *m_player = new QMediaPlayer(this);
m_player->setMedia(QUrl::fromLocalFile(QString::fromLocal8Bit("D:/try.mkv")));
m_videoW = new QVideoWidget(this);
m_layout->addWidget(m_videoW);
this->setLayout(m_layout);
m_player->setVideoOutput(m_videoW);
m_videoW->show();
m_player->play();
qDebug()<<"hello";
}
void MainWindow::paintEvent(QPaintEvent *){
QPainter painter(this);
painter.drawPixmap(0,0,width(),height(), m_videoW->currentPixmap());
}
This is the mainwindow.h file
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
void paintEvent(QPaintEvent*);
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
QVideoWidget *m_videoW;
};
The corresponding library is also added to the pro file:
QT += core gui
QT += multimedia
QT += multimediawidgets
I never found where the problem is, please help me find it! Thank you!
Test with qDebug, hello can output normally.
*The code has been displayed according to the principle of least recurrence.

Update MainWindow Qt from a non member function

I am doing an Application on Qt for my Internship and I have a problem.
The purpose of my Application is that I have a card connected by USB to my computer that sends CAN message.
I made an application in C++ on visual studio that received those CAN messages and printed them on the console with the help of a callback.
What I want to do know is to do the same thing but with a GUI application on Qt using the functions that I previously made (I didn't used classes in my visual studio project).
Iadded all my .cpp and .h files from my visual studio project into my QT project
So here is mainwindow.h file where I didn't changed anything. I just added a textLabel on my form.
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
The main.cpp is very basic.
MainWindow.cpp :
Here is the constructor when I open the communication
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Function created in Library.
open_com(...)
}
open_com opens the communication and call the callback each time a message is received
Definition of the callback
void callback (message id )
{
Here I want to call my TextLabel from my application
}
And my problem in this application is I don't know how to access my application from a function that is not part of the MainWindow class.
If someone already had this kind of problem and has the solution I would be very gratefull !
Thank you.

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

Qt Designer: Edit other window than mainwindow

I have a project which provides the user with a GUI via Qt. I designed it with the Qt Designer (integrated in the Qt Creator) and now I would like to add another window in order to let the user change settings.
Afaik I have to use a QWidget to create another window and now I'm wondering how I may edit this QWidget in Qt Designer because I am only able to design mainwindow.
My code looks like this:
mainwindow.hpp
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
// various slot calls
// action triggered when clicking an entry in the QMenu of mainwindow
void on_action_dummy();
private:
Ui::MainWindow *ui;
QWidget dummy;
};
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
// various implementations of the slot calls in mainwindow.hpp
void MainWindow::on_action_dummy()
{
dummy.show();
}
Maybe I need a own class for my new window? Is QWindow even the right class for this task?
You need to add a new UI file as well as header/class. There's an option for this in the "New File" dialog in Qt Creator (Qt Designer Form Class under the "Qt" sub-category on the sidebar). Then you open that up and instantiate the class like MainWindow in your program's entry point (int main()). Something like:
MySettingsDialog *dialog = new MySettingsDialog(this);
dialog->show();
You need to be careful how you instantiate it--mainly making sure the object will survive when it leaves the current scope (e.g. using a pointer if you are calling this in a method inside your class). Also, how you show/exec your dialog can vary. This is usually the case when you want a blocking (modal) dialog instead of a new "window".
Edit: To handle the memory management, you can set the WA_DeleteOnClose attribute:
dialog->setAttribute(Qt::WA_DeleteOnClose);

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.