From e2e107556dfb843fa0c3dc3e52695b34fdb40ba1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Sep 2016 14:23:54 +0200 Subject: tst_QGraphicsItem: Fix UB (invalid cast/member call) in prepareGeometryChange() Found by UBSan: tst_qgraphicsitem.cpp:5066:29: runtime error: downcast of address 0x2afcb006c7f0 which does not point to an object of type 'GeometryChanger' 0x2afcb006c7f0: note: object is of type 'QGraphicsRectItem' 00 00 00 00 d8 64 ca 98 fc 2a 00 00 40 a9 0b b0 fc 2a 00 00 75 65 29 00 00 00 00 00 35 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QGraphicsRectItem' #0 0x4c5f1c in tst_QGraphicsItem::prepareGeometryChange() tst_qgraphicsitem.cpp:5066 Fix by actually instantiating a GeometryChanger, which incidentally is the pattern used by paint() a few lines below, too. While at it, allocate the item on the stack (as is done in paint()) and create a local QRectF variable to avoid repeating the same magic numbers over and over again. Change-Id: If5a3d56511000a17703d78d7dd1f0ea072b8bc11 Reviewed-by: Thiago Macieira --- .../graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 835aeaa4df..8ee9ffe294 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -5065,9 +5065,10 @@ void tst_QGraphicsItem::sceneEventFilter() delete ti; } -class GeometryChanger : public QGraphicsItem +class GeometryChanger : public QGraphicsRectItem { public: + explicit GeometryChanger(QRectF r) : QGraphicsRectItem(r) {} void changeGeometry() { prepareGeometryChange(); } }; @@ -5076,10 +5077,12 @@ void tst_QGraphicsItem::prepareGeometryChange() { { QGraphicsScene scene; - QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); - QVERIFY(scene.items(QRectF(0, 0, 100, 100)).contains(item)); - ((GeometryChanger *)item)->changeGeometry(); - QVERIFY(scene.items(QRectF(0, 0, 100, 100)).contains(item)); + const QRectF rect(0, 0, 100, 100); + GeometryChanger item(rect); + scene.addItem(&item); + QVERIFY(scene.items(rect).contains(&item)); + item.changeGeometry(); + QVERIFY(scene.items(rect).contains(&item)); } } -- cgit v1.2.3 From 8cd28ea8850c5365c47dd65de16f528e2e223835 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 15 Sep 2016 14:07:07 +0200 Subject: QGuiApplication, platform plugins: don't modify AA_DontUseNativeMenuBar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default should be false, meaning the application will prefer to use a native menubar if the platform supports it. The application author can set it to true if he wants to always use a Qt-rendered menubar instead; or, he can call QMenuBar::setNativeMenuBar(). Qt and its plugins should not override the author's wishes. Instead, if the platform plugin cannot create a native menubar for whatever reason, createPlatformMenuBar() will return null, and QMenuBar will fall back to using a Qt menubar instead. The application can check the result via QMenuBar::isNativeMenuBar(). QMdiArea when maximized inside a QMainWindow with an empty title does not replace the main window's title if we are using native menus. This behavior turned out to be the same on Unity as it is on macOS, so the autotest needed adjustment to expect that behavior whenever the menubar is native, not only on certain platforms. tst_QMenuBar::allowActiveAndDisabled() tests a standalone QMenuBar. In f92f78094 it was disabled on macOS, but on Ubuntu it passes as long as we force it to be a non-native menubar, so it should pass that way on macOS too. Removed unused variable RESET to fix warning. Task-number: QTBUG-54793 Change-Id: I716e40da709f96331cbbf25213bd7bc153e4dbe2 Reviewed-by: Morten Johan Sørvig --- .../widgets/qmdisubwindow/tst_qmdisubwindow.cpp | 76 ++++++++++------------ .../auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 9 +-- 2 files changed, 41 insertions(+), 44 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp index fe5c3a14a0..3fbb9a3f3f 100644 --- a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp +++ b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp @@ -359,25 +359,25 @@ void tst_QMdiSubWindow::mainWindowSupport() mainWindow.show(); mainWindow.menuBar()->setVisible(true); qApp->setActiveWindow(&mainWindow); - - // QMainWindow's window title is empty -#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) - { - QCOMPARE(mainWindow.windowTitle(), QString()); - QMdiSubWindow *window = workspace->addSubWindow(new QPushButton(QLatin1String("Test"))); - QString expectedTitle = QLatin1String("MainWindow's title is empty"); - window->setWindowTitle(expectedTitle); - QCOMPARE(window->windowTitle(), expectedTitle); - window->showMaximized(); - QVERIFY(window->isMaximized()); - QCOMPARE(window->windowTitle(), expectedTitle); - QCOMPARE(mainWindow.windowTitle(), expectedTitle); - window->showNormal(); - QCOMPARE(window->windowTitle(), expectedTitle); - QCOMPARE(mainWindow.windowTitle(), QString()); - window->close(); + bool nativeMenuBar = mainWindow.menuBar()->isNativeMenuBar(); + + // QMainWindow's window title is empty, so on a platform which does NOT have a native menubar, + // the maximized subwindow's title is imposed onto the main window's titlebar. + if (!nativeMenuBar) { + QCOMPARE(mainWindow.windowTitle(), QString()); + QMdiSubWindow *window = workspace->addSubWindow(new QPushButton(QLatin1String("Test"))); + QString expectedTitle = QLatin1String("MainWindow's title is empty"); + window->setWindowTitle(expectedTitle); + QCOMPARE(window->windowTitle(), expectedTitle); + window->showMaximized(); + QVERIFY(window->isMaximized()); + QCOMPARE(window->windowTitle(), expectedTitle); + QCOMPARE(mainWindow.windowTitle(), expectedTitle); + window->showNormal(); + QCOMPARE(window->windowTitle(), expectedTitle); + QCOMPARE(mainWindow.windowTitle(), QString()); + window->close(); } -#endif QString originalWindowTitle = QString::fromLatin1("MainWindow"); mainWindow.setWindowTitle(originalWindowTitle); @@ -413,16 +413,16 @@ void tst_QMdiSubWindow::mainWindowSupport() window->showMaximized(); qApp->processEvents(); QVERIFY(window->isMaximized()); -#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) - QVERIFY(window->maximizedButtonsWidget()); - QCOMPARE(window->maximizedButtonsWidget(), mainWindow.menuBar()->cornerWidget(Qt::TopRightCorner)); - QVERIFY(window->maximizedSystemMenuIconWidget()); - QCOMPARE(window->maximizedSystemMenuIconWidget(), qobject_cast(mainWindow.menuBar() - ->cornerWidget(Qt::TopLeftCorner))); - const QString expectedTitle = originalWindowTitle + QLatin1String(" - [") - + window->widget()->windowTitle() + QLatin1Char(']'); - QCOMPARE(mainWindow.windowTitle(), expectedTitle); -#endif + if (!nativeMenuBar) { + QVERIFY(window->maximizedButtonsWidget()); + QCOMPARE(window->maximizedButtonsWidget(), mainWindow.menuBar()->cornerWidget(Qt::TopRightCorner)); + QVERIFY(window->maximizedSystemMenuIconWidget()); + QCOMPARE(window->maximizedSystemMenuIconWidget(), + qobject_cast(mainWindow.menuBar()->cornerWidget(Qt::TopLeftCorner))); + const QString expectedTitle = originalWindowTitle + QLatin1String(" - [") + + window->widget()->windowTitle() + QLatin1Char(']'); + QCOMPARE(mainWindow.windowTitle(), expectedTitle); + } // Check that nested child windows don't set window title nestedWorkspace->show(); @@ -436,15 +436,14 @@ void tst_QMdiSubWindow::mainWindowSupport() QVERIFY(!nestedWindow->maximizedButtonsWidget()); QVERIFY(!nestedWindow->maximizedSystemMenuIconWidget()); -#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) && !defined(Q_OS_QNX) - QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") - .arg(originalWindowTitle, window->widget()->windowTitle())); -#endif + if (!nativeMenuBar) { + QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") + .arg(originalWindowTitle, window->widget()->windowTitle())); + } } -#if defined(Q_OS_MAC) || defined(Q_OS_WINCE) - return; -#endif + if (nativeMenuBar) + return; workspace->activateNextSubWindow(); qApp->processEvents(); @@ -1911,14 +1910,14 @@ void tst_QMdiSubWindow::mdiArea() void tst_QMdiSubWindow::task_182852() { -#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) - QMdiArea *workspace = new QMdiArea; QMainWindow mainWindow; mainWindow.setCentralWidget(workspace); mainWindow.show(); mainWindow.menuBar()->setVisible(true); qApp->setActiveWindow(&mainWindow); + if (mainWindow.menuBar()->isNativeMenuBar()) + return; // The main window's title is not overwritten if we have a native menubar (macOS, Unity etc.) QString originalWindowTitle = QString::fromLatin1("MainWindow - [foo]"); mainWindow.setWindowTitle(originalWindowTitle); @@ -1954,9 +1953,6 @@ void tst_QMdiSubWindow::task_182852() QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") .arg(originalWindowTitle, window->widget()->windowTitle())); - - -#endif } void tst_QMdiSubWindow::task_233197() diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 4b4bec9920..185bfc02a0 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -93,7 +93,6 @@ private slots: #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void accel(); void activatedCount(); - void allowActiveAndDisabled(); void check_accelKeys(); void check_cursorKeys1(); @@ -102,6 +101,9 @@ private slots: void check_escKey(); #endif +#ifndef Q_OS_WINCE + void allowActiveAndDisabled(); +#endif void check_endKey(); void check_homeKey(); @@ -164,8 +166,6 @@ void tst_QMenuBar::getSetCheck() #include -const int RESET = 0; - /*! Test plan: insertItem (all flavors and combinations) @@ -920,10 +920,11 @@ void tst_QMenuBar::check_escKey() // QCOMPARE(m_complexActionTriggerCount['h'], (uint)itemH_count); // } -#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) +#ifndef Q_OS_WINCE void tst_QMenuBar::allowActiveAndDisabled() { QMenuBar menuBar; + menuBar.setNativeMenuBar(false); // Task 241043 : check that second menu is activated if only // disabled menu items are added -- cgit v1.2.3 From 77eafa8d890bc80813159ad29ba3a4e1909866fd Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 26 Sep 2016 21:37:49 +0200 Subject: Plug memleaks in tst_QBoxLayout In sizeConstraints(), QLayout::takeAt(), as the name suggests, doesn't actually delete the item. We have to do that ourselves. Likewise, in replaceWidget(), QLayout::replaceWidget() also doesn't delete the affected item, but returns it. That's spectacularly bad API design, but the leak is easy to fix: just delete the return value. Change-Id: I8dcbc59898949eabce766cda2c0edae2e1f2799e Reviewed-by: Friedemann Kleint --- tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index aeaf1e7bf0..ed5b763b0f 100644 --- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp +++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp @@ -188,7 +188,7 @@ void tst_QBoxLayout::sizeConstraints() window.show(); QTest::qWaitForWindowExposed(&window); QSize sh = window.sizeHint(); - lay->takeAt(1); + delete lay->takeAt(1); QVERIFY(sh.width() >= window.sizeHint().width() && sh.height() >= window.sizeHint().height()); @@ -517,7 +517,7 @@ void tst_QBoxLayout::replaceWidget() QCOMPARE(boxLayout->indexOf(replaceFrom), 1); QCOMPARE(boxLayout->indexOf(replaceTo), -1); - boxLayout->replaceWidget(replaceFrom, replaceTo); + delete boxLayout->replaceWidget(replaceFrom, replaceTo); QCOMPARE(boxLayout->indexOf(replaceFrom), -1); QCOMPARE(boxLayout->indexOf(replaceTo), 1); -- cgit v1.2.3 From b827b8ccf7311d8bc3551501a5faa6d456da052b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 26 Sep 2016 21:37:49 +0200 Subject: Plug memleaks in tst_QGridLayout In setMinAndMaxSize(), QLayout::removeItem() doesn't actually delete the removed item. We have to do that ourselves (RAII not necessary, since the spacer is owned by the layout until we remove it). In distributeMultiCell(), allocate the QStyle subclass on the stack so the compiler cleans it up properly on all exit paths (was: unconditional leak). Change-Id: I24f8f11af2bfc5abf78f9aab0139dcfe0187402b Reviewed-by: Friedemann Kleint --- tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp index 1e67c675ef..255481031b 100644 --- a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp +++ b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp @@ -353,6 +353,8 @@ void tst_QGridLayout::setMinAndMaxSize() layout.removeItem(spacer); + delete spacer; + spacer = Q_NULLPTR; rightChild.hide(); QApplication::sendPostedEvents(0, 0); @@ -1601,10 +1603,10 @@ void tst_QGridLayout::contentsRect() void tst_QGridLayout::distributeMultiCell() { QWidget w; - Qt42Style *style = new Qt42Style(); - style->spacing = 9; + Qt42Style style; + style.spacing = 9; - w.setStyle(style); + w.setStyle(&style); QGridLayout grid; w.setLayout(&grid); -- cgit v1.2.3 From 3379ace11b30d8e9a2c9b45789561ac44bf29c06 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 4 Aug 2016 16:41:12 +0200 Subject: QDateTimeEdit: synchronize time-spec before initializing display QDateTimeEdit ignores the time-spec of its date-time value, using its own time-spec instead; mostly, this works because it first conforms the value to its own time-spec. However, during construction, before doing this, it set up its display data, which could leave it with a different time (rather than a different representation of the given time) than it was asked to use. Moved the updateTimeSpec() calls to immediately after setting value in QDateTimeEditPrivate::init() to ensure correct handling. Added test. Task-number: QTBUG-54781 Change-Id: I3b07c10997abb858fc0b40558bff96e3fdabbd83 Reviewed-by: Jesus Fernandez Reviewed-by: Marc Mutz --- tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index d41398046f..08a28f3ea0 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -252,6 +252,7 @@ private slots: void timeSpec_data(); void timeSpec(); void timeSpecBug(); + void timeSpecInit(); void monthEdgeCase(); void setLocale(); @@ -3215,6 +3216,13 @@ void tst_QDateTimeEdit::timeSpecBug() QCOMPARE(oldText, testWidget->text()); } +void tst_QDateTimeEdit::timeSpecInit() +{ + QDateTime utc(QDate(2000, 1, 1), QTime(12, 0, 0), Qt::UTC); + QDateTimeEdit widget(utc); + QCOMPARE(widget.dateTime(), utc); +} + void tst_QDateTimeEdit::cachedDayTest() { testWidget->setDisplayFormat("MM/dd"); -- cgit v1.2.3 From 5571d2bf62a69f2422a849a8d0cd2c40c35b8d47 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Sep 2016 13:59:37 +0200 Subject: tst_QApplication: Fix UBs (invalid cast) in focusMouseClick() Found by UBSan: tst_qapplication.cpp:1754:48: runtime error: member access within address 0x7ffda11f2220 which does not point to an object of type 'SpontaneousEvent' 0x7ffda11f2220: note: object is of type 'QMouseEvent' The code attempted to model the layout of a QEvent with another class that allows public access to the memory location that (hopefully) corresponds to QEvent::spont, gaining access by casting a QEvent object to that specifically-crafted class. Fix by the using the existing QSpontaneKeyEvent::setSpontaneous() call, which, despite its name, works for all QEvent subclasses, and which has already been fixed to not invoke UB (in bc087db). Change-Id: I7db8b8a8a823f7d61ab17375142d19dc3874fea5 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../kernel/qapplication/tst_qapplication.cpp | 25 +++------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 878136b4a0..87a189fc87 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -1769,25 +1769,6 @@ void tst_QApplication::focusOut() QTest::qWait(2000); } -class SpontaneousEvent -{ - Q_GADGET - QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - Q_ENUMS(Type) -public: - enum Type { - Void - }; - - virtual ~SpontaneousEvent() {} - - QEventPrivate *d; - ushort t; - - ushort posted : 1; - ushort spont : 1; -}; - void tst_QApplication::focusMouseClick() { int argc = 1; @@ -1805,14 +1786,14 @@ void tst_QApplication::focusMouseClick() // now send a mouse button press event and check what happens with the focus // it should be given to the parent widget QMouseEvent ev(QEvent::MouseButtonPress, QPointF(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); - reinterpret_cast(&ev)->spont = 1; + QSpontaneKeyEvent::setSpontaneous(&ev); QVERIFY(ev.spontaneous()); qApp->notify(&w2, &ev); QCOMPARE(QApplication::focusWidget(), &w); // then we give the inner widget strong focus -> it should get focus w2.setFocusPolicy(Qt::StrongFocus); - reinterpret_cast(&ev)->spont = 1; + QSpontaneKeyEvent::setSpontaneous(&ev); QVERIFY(ev.spontaneous()); qApp->notify(&w2, &ev); QTRY_COMPARE(QApplication::focusWidget(), &w2); @@ -1820,7 +1801,7 @@ void tst_QApplication::focusMouseClick() // now back to tab focus and click again (it already had focus) -> focus should stay // (focus was revoked as of QTBUG-34042) w2.setFocusPolicy(Qt::TabFocus); - reinterpret_cast(&ev)->spont = 1; + QSpontaneKeyEvent::setSpontaneous(&ev); QVERIFY(ev.spontaneous()); qApp->notify(&w2, &ev); QCOMPARE(QApplication::focusWidget(), &w2); -- cgit v1.2.3 From da2c73ad2b84ef9d58a23fa880c05ca33a0053e5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Sep 2016 10:22:46 +0200 Subject: Plug memleaks in tst_QWidget We need to delete the style returned from QStyleFactory::create() ourselves, so put them into a QScopedPointer. The alternative would have been to create this once, as a member of tst_QWidget, but this is the minimal approach that ensures behavior just as the old code, but without the leak. Change-Id: I527f1031c57be6f05942f4acc057e7dae1af2571 Reviewed-by: Thiago Macieira --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 50d7b258bc..e00e575c36 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -5135,7 +5135,8 @@ void tst_QWidget::moveChild() ColorWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint); // prevent custom styles - parent.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); + parent.setStyle(style.data()); ColorWidget child(&parent, Qt::Widget, Qt::blue); #ifndef Q_OS_WINCE @@ -5184,7 +5185,8 @@ void tst_QWidget::showAndMoveChild() QSKIP("Wayland: This fails. Figure out why."); QWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint); // prevent custom styles - parent.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); + parent.setStyle(style.data()); QDesktopWidget desktop; QRect desktopDimensions = desktop.availableGeometry(&parent); @@ -6680,7 +6682,9 @@ void tst_QWidget::renderWithPainter() { QWidget widget(0, Qt::Tool); // prevent custom styles - widget.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + + const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); + widget.setStyle(style.data()); widget.show(); widget.resize(70, 50); widget.setAutoFillBackground(true); -- cgit v1.2.3