Qt application works fine on MacOSX, Windows Access Violation

So, I came across a problem that I can’t solve for a while. I am writing a Qt application in C ++ and developing MacOSX on which it works great. However, as I test the code in windows, I encounter the following access violation when I close OR cancel the QDialog child that I have:

Unhandled exception at 0x5ce6b1ea (QtGuid4.dll) in MyApp.exe: 0xC0000005: Access violation reading location 0xfeeefefa.

Debugging this, I see that it crashes after many Qt api calls, eventually making its way to QWindowSurface_Raster.cpp. Here is the Qt library code with which it crashes:

 #endif { QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft(); HDC widget_dc = widget->getDC(); QRect wbr = br.translated(-wOffset); BitBlt(widget_dc, wbr.x(), wbr.y(), wbr.width(), wbr.height(), /*CRASH HERE!*/ d->image->hdc, br.x() + offset.x(), br.y() + offset.y(), SRCCOPY); widget->releaseDC(widget_dc); } 

And finally, here is my code where I call qdialog:

 void MainWindow::prefDialog() { prefD = new PreferenceDialog(this); prefD->exec(); } /* crashes here, after I hit cancel/ok on dialog and it leaves exec */ 

PreferenceDialog.h:

 class PreferenceDialog : public QDialog { Q_OBJECT public: PreferenceDialog(QWidget *parent); ..... 

PreferenceDialog.c

 PreferenceDialog::PreferenceDialog(QWidget *parent) : QDialog(parent) { .... connect(okayButton, SIGNAL(released()), this, SLOT(okayClicked())); connect(addKeyButton, SIGNAL(released()), this, SLOT(addClicked())); connect(cancelButton, SIGNAL(released()), this, SLOT(cancelClicked())); .... 

I can show you my PreferenceDialog code or any other code, but I think it will just inflate the situation. PreferenceDialog does nothing but the one shown, and I do not override any function like exec (), etc. The stack trace is pretty bloated, so I won’t post messages, it's just a bunch of calls to Qtguid4.dll after exec () ends (about 10), until it comes to this crash in QWindowRaster.

Let me know if any other information is needed. I am new to Qt, so it’s hard for me to understand this, any help would be greatly appreciated, thanks!

+4
source share
1 answer

I called QDialog :: destroy () to close the window instead of QDialog :: close (). This caused a null pointer exception when Qt finished QDialog :: exec () and caused a crash on Windows. Changing the call to close () fixes the problem.

Thanks to HostileFork for the tips.

+4
source

Source: https://habr.com/ru/post/1437505/


All Articles