PDA

View Full Version : Qwizard crashed when created in a slot



joshlareau
15th August 2007, 16:37
I'm trying to use the QWizard class introduced in Qt4.3.0 but whenever I try to create my QWizard derived class in a slot, I get an access violation deep in the Qt library:

qwizard_win.cpp

bool QVistaHelper::handleWinEvent(MSG *message, long *result)
{
bool status = false;
if (wizard->wizardStyle() == QWizard::AeroStyle) {
status = winEvent(message, result);
if (message->message == WM_NCCALCSIZE) {
if (status)
collapseTopFrameStrut();
} else if (message->message == WM_NCPAINT) {
wizard->update();
}
}
return status;
}

It appears as if the wizard pointer is no longer valid. Here is my calling code:


void MyApp::testSlot()
{
NewProjectWizard* projwizard = new NewProjectWizard( this );
projwizard->show();
}

This code works fine anywhere but in a connected slot. Has anyone else experienced this? Could someone else test this and see if I'm crazy? I have Qt 4.3.0 compiled for Microsft Visual Studio 2005 installed and I'm running Windows XP, not Vista. Maybe Qt4.3.1 fixes this problem but I didn't see anything in the change log. Any help would be appreciated, thanks.

jpn
15th August 2007, 16:54
Could someone else test this and see if I'm crazy?
Could you prepare a minimal compilable example that reproduces the problem so we can test it?

joshlareau
15th August 2007, 17:24
It looks like it's not just with any connected slot, but only slots connected to widgets on a toolbar or to QActions signals.

Here is the minimally compilable source code that will recreate the problem:


//main.cpp
#include <QtGui/QApplication>
#include "example.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
example w;
w.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}


//example.h
#include <QtGui/QMainWindow>
#include <QAction>
#include <QToolBar>
class example: public QMainWindow
{
Q_OBJECT

public:
example( QWidget *parent = 0, Qt::WFlags flags = 0 );

public slots:
void TestSlot();

private:
QToolBar *mainToolBar;
};


//Example.cpp
#include "example.h"
#include <QWizard>
#include <QToolButton>
example::example(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
mainToolBar = new QToolBar( this );

QToolButton* tstButton = new QToolButton;
tstButton->setText( "Test" );
mainToolBar->addWidget( tstButton );

connect( tstButton, SIGNAL( clicked() ), this, SLOT( TestSlot() ) );
}

void example::TestSlot()
{
QWizard* myWizard = new QWizard( this );
myWizard->show();
}

jpn
15th August 2007, 17:33
Hmm, for me it runs fine with WinXP / MSVC 2005 / Qt 4.3.0. Could you copy and paste contents of call stack by the time it crashes?

joshlareau
15th August 2007, 17:40
Here is the call stack. I've attached my source files too if that helps.


mincompex.exe!QVistaHelper::handleWinEvent(tagMSG * message=0x0012b38c, long * result=0x0012b3b0) Line 374 + 0x3 bytes C++
mincompex.exe!QWizard::winEvent(tagMSG * message=0x0012b38c, long * result=0x0012b3b0) Line 2820 C++
mincompex.exe!QtWndProc(HWND__ * hwnd=0x00020784, unsigned int message=128, unsigned int wParam=0, long lParam=0) Line 1366 + 0x18 bytes C++
user32.dll!7e418734()
[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]
user32.dll!7e418816()
user32.dll!7e41b89b()
user32.dll!7e42f3cc()
mincompex.exe!QWidgetPrivate::setWindowIcon_sys(bo ol forceReset=false) Line 774 C++
mincompex.exe!QWidget::create(HWND__ * window=0x00000000, bool initializeWindow=true, bool destroyOldWindow=true) Line 1107 C++
mincompex.exe!QWidgetPrivate::createWinId(HWND__ * winid=0x00000000) Line 1826 C++
mincompex.exe!QWidgetPrivate::createWinId(HWND__ * winid=0x00000000) Line 1809 C++
mincompex.exe!QWidgetPrivate::createWinId(HWND__ * winid=0x00000000) Line 1809 C++
mincompex.exe!QWidget::winId() Line 1794 C++
mincompex.exe!QAccessible::updateAccessibility(QOb ject * o=0x016986e8, int who=0, QAccessible::Event reason=NameChanged) Line 161 + 0xe bytes C++
mincompex.exe!QAbstractButton::setText(const QString & text={...}) Line 616 + 0x10 bytes C++
mincompex.exe!QWizardPrivate::ensureButton(QWizard ::WizardButton which=BackButton) Line 1125 + 0x61 bytes C++
mincompex.exe!QWizardPrivate::init() Line 585 C++
mincompex.exe!QWizard::QWizard(QWidget * parent=0x0012fe9c, QFlags<enum Qt::WindowType> flags={...}) Line 1915 C++
mincompex.exe!mincompex::TestSlot() Line 20 + 0x33 bytes C++
mincompex.exe!mincompex::qt_metacall(QMetaObject:: Call _c=InvokeMetaMethod, int _id=0, void * * _a=0x0012be74) Line 66 C++
mincompex.exe!QMetaObject::activate(QObject * sender=0x01634c88, int from_signal_index=29, int to_signal_index=30, void * * argv=0x0012be74) Line 3066 + 0x46 bytes C++
mincompex.exe!QMetaObject::activate(QObject * sender=0x01634c88, const QMetaObject * m=0x00f9e0a4, int from_local_signal_index=2, int to_local_signal_index=3, void * * argv=0x0012be74) Line 3145 + 0x15 bytes C++
mincompex.exe!QAbstractButton::clicked(bool _t1=false) Line 180 + 0x16 bytes C++
mincompex.exe!QAbstractButtonPrivate::emitClicked( ) Line 519 C++
mincompex.exe!QAbstractButtonPrivate::click() Line 511 C++
mincompex.exe!QAbstractButton::mouseReleaseEvent(Q MouseEvent * e=0x0012c4b4) Line 1088 C++
mincompex.exe!QToolButton::mouseReleaseEvent(QMous eEvent * e=0x0012c4b4) Line 644 C++
mincompex.exe!QWidget::event(QEvent * event=0x0012c4b4) Line 6032 C++
mincompex.exe!QAbstractButton::event(QEvent * e=0x0012c4b4) Line 1050 C++
mincompex.exe!QToolButton::event(QEvent * e=0x0012c4b4) Line 1061 C++
mincompex.exe!QApplicationPrivate::notify_helper(Q Object * receiver=0x01634c88, QEvent * e=0x0012c4b4) Line 3538 + 0x11 bytes C++
mincompex.exe!QApplication::notify(QObject * receiver=0x01634c88, QEvent * e=0x0012c4b4) Line 3237 + 0x2f bytes C++
mincompex.exe!QCoreApplication::notifyInternal(QOb ject * receiver=0x01634c88, QEvent * event=0x0012c4b4) Line 510 C++
mincompex.exe!QCoreApplication::sendSpontaneousEve nt(QObject * receiver=0x01634c88, QEvent * event=0x0012c4b4) Line 189 + 0x38 bytes C++
mincompex.exe!QETWidget::translateMouseEvent(const tagMSG & msg={...}) Line 2746 + 0x13 bytes C++
mincompex.exe!QtWndProc(HWND__ * hwnd=0x00020786, unsigned int message=514, unsigned int wParam=0, long lParam=524314) Line 1378 + 0xc bytes C++
user32.dll!7e418734()
user32.dll!7e418816()
user32.dll!7e4189cd()
user32.dll!7e418a10()
mincompex.exe!QEventDispatcherWin32::processEvents (QFlags<enum QEventLoop::ProcessEventsFlag> flags={...}) Line 521 + 0x18 bytes C++
ntdll.dll!7c96cd11()
ntdll.dll!7c960af8()
ntdll.dll!7c960bf0()
ntdll.dll!7c960bcc()
mincompex.exe!_free_base(void * pBlock=0x00000004) Line 109 + 0x12 bytes C
mincompex.exe!_free_dbg(void * pUserData=0x00000000, int nBlockUse=22111800) Line 1225 + 0x7 bytes C++
mincompex.exe!_free_dbg(void * pUserData=0x01694984, int nBlockUse=2090195884) Line 1222 + 0xc bytes C++
ntdll.dll!7c95db5c()
ntdll.dll!7c96cd11()
ntdll.dll!7c960af8()
ntdll.dll!7c960bf0()
ntdll.dll!7c960bcc()
mincompex.exe!QRegion::~QRegion() Line 200 + 0xb bytes C++
mincompex.exe!QETWidget::translatePaintEvent(const tagMSG & msg={...}) Line 3087 + 0x13 bytes C++
mincompex.exe!QtWndProc(HWND__ * hwnd=0x00000008, unsigned int message=0, unsigned int wParam=22085632, long lParam=22085632) Line 1668 + 0xc bytes C++
ntdll.dll!7c96cd11()
ntdll.dll!7c960af8()
ntdll.dll!7c960bf0()
ntdll.dll!7c9106eb()
mincompex.exe!_heap_alloc_base(unsigned int size=17367936) Line 105 + 0x28 bytes C
mincompex.exe!_unlock(int locknum=17367936) Line 376 C

jpn
15th August 2007, 17:54
Did you compile Qt by hand? For some reason your wizard has QWizard::AeroStyle set, even if it should be only possible on Vista. I'm sure you can get past the problem by setting another wizard style by hand but I'm suspecting something might be wrong with your Qt installation.

joshlareau
15th August 2007, 19:57
I did compile Qt by hand. Was I supposed to specify windows XP somewhere during configure? I've tried explicitly setting the QWizard style but it didn't seem to fix it.

joshlareau
15th August 2007, 20:48
I think I may have found a workaround. In my slot I was doing the following:

QWizard* myWizard = new QWizard( this );

However, if I make myWizard a member of my class and I move that line outside the slot, say to the constructor of my class and then only call myWizard->show() in the slot, everything works fine.

jpn
15th August 2007, 21:23
I did compile Qt by hand. Was I supposed to specify windows XP somewhere during configure?
It should be all detected just fine by default but configure output could have shown something suspicious.


I've tried explicitly setting the QWizard style but it didn't seem to fix it.
That's weird, because the crashing line (qwizard_win.cpp, 374) gets never executed if wizard style is something else than QWizard::AeroStyle. Does it crash somewhere else?

luf
15th January 2008, 10:16
I was just wondering if anyone found a solution to this one, as I seem to have the exact same issue right now...