我在Windows SDK 10.0.17763.0上使用Qt 5.12.8
我的应用程序在退出期间崩溃,并且堆栈跟踪指示删除QWinExtra
时出现问题。似乎正在发生两次删除。 QWindow
检查句柄时,QWinThumbnailToolBarPrivate::hasHandle()
已被删除。
我需要做些特别的事情来适当破坏QWinThumbnailToolBar
吗?
问题:
引发异常:读取访问冲突。
d为0xFFFFFFFFFFFFFFFF7F。
QPlatformWindow *QWindow::handle() const
{
Q_D(const QWindow);
return d->platformWindow;
}
下面的堆栈跟踪:
Qt5Guid.dll!QWindow::handle() Line 1929 C++
Qt5WinExtrasd.dll!QWinThumbnailToolBarPrivate::hasHandle() Line 460 C++
Qt5WinExtrasd.dll!QWinThumbnailToolBarPrivate::handle() Line 465 C++
Qt5WinExtrasd.dll!QWinThumbnailToolBarPrivate::nativeEventFilter(const QByteArray & __formal, void * message, long * result) Line 549 C++
Qt5Cored.dll!QAbstractEventDispatcher::filterNativeEvent(const QByteArray & eventType, void * message, long * result) Line 484 C++
[External Code]
Qt5Guid.dll!QWindowPrivate::destroy() Line 1914 C++
Qt5Guid.dll!QWindow::destroy() Line 1864 C++
Qt5Widgetsd.dll!QWidgetPrivate::deleteTLSysExtra() Line 1891 C++
Qt5Widgetsd.dll!QWidget::destroy(bool destroyWindow, bool destroySubWindows) Line 12515 C++
Qt5Widgetsd.dll!QApplication::~QApplication() Line 798 C++
我的实施
我有一个名为QDialog
的简单DDialog
子类,具有以下实现:
DDialog::DDialog(QWidget* parent)
: QDialog(parent), m_pThumbnailToolbar(nullptr), m_pLockOnTopToolButton(nullptr)
{
}
void DDialog::ToggleKeepDialogLockedOnTop()
{
if (windowFlags() & Qt::WindowStaysOnTopHint)
{
setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
m_pLockOnTopToolButton->setToolTip("Enable Window Lock");
m_pLockOnTopToolButton->setIcon(QIcon(":/appbase/Resources/window_unlocked.png"));
}
else
{
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
m_pLockOnTopToolButton->setToolTip("Disable Window Lock");
m_pLockOnTopToolButton->setIcon(QIcon(":/appbase/Resources/window_locked.png"));
}
// https://doc.qt.io/qt-5/qwidget.html#windowFlags-prop
// Per Qt Documentation, setWindowFlags causes for the widget to be hidden
// for this reason it needs to be shown again
show();
}
DDialog::~DDialog()
{
close();
}
void DDialog::SetupWinThumbnailToolbar()
{
if (windowHandle() && !m_pThumbnailToolbar)
{
m_pThumbnailToolbar = new QWinThumbnailToolBar(this);
m_pThumbnailToolbar->setWindow(windowHandle());
m_pLockOnTopToolButton = new QWinThumbnailToolButton(m_pThumbnailToolbar);
m_pLockOnTopToolButton->setToolTip("Enable Window Lock");
m_pLockOnTopToolButton->setIcon(QIcon(":/appbase/Resources/window_unlocked.png"));
m_pLockOnTopToolButton->setDismissOnClick(true);
connect(m_pLockOnTopToolButton, &QWinThumbnailToolButton::clicked, this, &DDialog::ToggleKeepDialogLockedOnTop);
m_pThumbnailToolbar->addButton(m_pLockOnTopToolButton);
}
}
它的命名方式
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
DDialog* pDialog1 = new DDialog;
QObject::connect(&a, &QApplication::aboutToQuit, pDialog1, &QObject::deleteLater);
pDialog1->show();
pDialog1->SetupWinThumbnailToolbar();
DDialog* pDialog2 = new DDialog;
QObject::connect(&a, &QApplication::aboutToQuit, pDialog2, &QObject::deleteLater);
pDialog2->show();
pDialog2->SetupWinThumbnailToolbar();
return a.exec();
}