Why does QT DLL process calls this class from .exe process give an access violation?
-
the following link Error screenshot
link Error screenshot//dll code
#include <QtWidgets/QWidget> #include "qtdll_global.h" class QTDLL_EXPORT widgetdll : public QWidget { Q_OBJECT public: widgetdll(QWidget *parent = 0,HWND hwnd = 0); ~widgetdll(); }; #include "widgetdll.h" #include <QWindow> #include <QMessageBox> widgetdll::widgetdll(QWidget *parent,HWND hwnd) : QWidget(parent) { setFixedSize(600, 400); // QWindow *container = QWindow::fromWinId((WId)hwnd); container->show(); } widgetdll::~widgetdll() { }
.exe code
#include <QtWidgets/QMainWindow> #include "ui_callDll.h" class callDll : public QMainWindow { Q_OBJECT public: callDll(QWidget *parent = 0); ~callDll(); private: Ui::callDllClass ui; }; #include "callDll.h" #include "widgetdll.h" #include <QtWidgets/QLayout> #include <QWindow> #include <QPushButton> callDll::callDll(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); QWidget *pUserWidget = new QWidget; pUserWidget->setObjectName(QString::fromUtf8("Sub Window")); pUserWidget->setFixedSize(600, 400); pUserWidget->setWindowTitle("Sub Window"); WId hwndParentWidget = pUserWidget->effectiveWinId(); widgetdll * p = new widgetdll(0,(HWND)hwndParentWidget); p->show(); setWindowTitle("Parent Window"); setObjectName("Parent Window"); } callDll::~callDll() { }
-
Hi
If you do
QWindow *container = QWindow::fromWinId((WId)hwnd);
if ( container )
container->show();does it still crash ?
-
Hi
If you do
QWindow *container = QWindow::fromWinId((WId)hwnd);
if ( container )
container->show();does it still crash ?
-
Cannot the following code be used in another process?
QWindow *container = QWindow::fromWinId((WId)hwnd);
@mirro said in Why does QT DLL process calls this class from .exe process give an access violation?:
fromWinId
Docs sounds like it can.
https://doc.qt.io/qt-5/qwindow.html#fromWinIdso if you check for NULL you no longer crash ?
-
@mirro said in Why does QT DLL process calls this class from .exe process give an access violation?:
fromWinId
Docs sounds like it can.
https://doc.qt.io/qt-5/qwindow.html#fromWinIdso if you check for NULL you no longer crash ?
-
If the null pointer is checked, the program does not crash.
Can't the following code be used in another process?
QWindow *container = QWindow::fromWinId((WId)hwnd);
-
@mirro
I don't mean that.
I've tested your code withQWidget *pUserWidget = new QWidget; pUserWidget->setObjectName(QString::fromUtf8("Sub Window")); pUserWidget->setFixedSize(600, 400); pUserWidget->setWindowTitle("Sub Window"); WId hwndParentWidget = pUserWidget->effectiveWinId(); qDebug() << hwndParentWidget;
And the value of
hwndParentWidget
is0
.
So I ask you if you've checked that.
If thehwnd
is0
, then it is reasonable that the result ofQWindow::fromWinId
isnullptr
. -
@mirro
I don't mean that.
I've tested your code withQWidget *pUserWidget = new QWidget; pUserWidget->setObjectName(QString::fromUtf8("Sub Window")); pUserWidget->setFixedSize(600, 400); pUserWidget->setWindowTitle("Sub Window"); WId hwndParentWidget = pUserWidget->effectiveWinId(); qDebug() << hwndParentWidget;
And the value of
hwndParentWidget
is0
.
So I ask you if you've checked that.
If thehwnd
is0
, then it is reasonable that the result ofQWindow::fromWinId
isnullptr
.@Bonnie
thank you.
is (HWND)hwndParentWidget null value?
How to convert WId to HWND?callDll::callDll(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); // QWidget *pUserWidget = new QWidget; pUserWidget->setObjectName(QString::fromUtf8("another progress widget")); pUserWidget->setFixedSize(600, 400); pUserWidget->setWindowTitle("another progress widget"); WId hwndParentWidget = pUserWidget->effectiveWinId(); widgetdll * p = new widgetdll(0,(HWND)hwndParentWidget); p->show(); }
widgetdll::widgetdll(QWidget *parent,HWND hwnd) : QWidget(parent) { // QWindow *container = QWindow::fromWinId((WId)hwnd); if (container) container->show(); }
-
@Bonnie
thank you.
is (HWND)hwndParentWidget null value?
How to convert WId to HWND?callDll::callDll(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); // QWidget *pUserWidget = new QWidget; pUserWidget->setObjectName(QString::fromUtf8("another progress widget")); pUserWidget->setFixedSize(600, 400); pUserWidget->setWindowTitle("another progress widget"); WId hwndParentWidget = pUserWidget->effectiveWinId(); widgetdll * p = new widgetdll(0,(HWND)hwndParentWidget); p->show(); }
widgetdll::widgetdll(QWidget *parent,HWND hwnd) : QWidget(parent) { // QWindow *container = QWindow::fromWinId((WId)hwnd); if (container) container->show(); }