Unhandled exception sending event to qwidget in DLL
-
Hi,
I have a very simple QWidget based class (call it myWidget) that I compile into a -QT- Qt plugin DLL (not a -QT- Qt designer plugin). MyWidget overrides only the QWidget constructor and paintEvent. The plugin interface provides a function:
@
virtual QWidget *createUiWidget(QWidget *parent, QString widgetName, QPoint position) = 0;
@
where in you pass a pointer to the widget that will be the parent of myWidget, the name of the widget (the DLL resolves this name to the myWidget class) and the position where to draw the widget on the parent. The DLL creates an instance of myWidget using the provided info.I first developed myWidget and compiled it in the main EXE. It works fine there. After I move it to the DLL I get this error after myWidget's constructor is called but before myWidget's paintEvent is called:
Unhandled exception at 0x65071539 (QtGuid4.dll) in pluginMain.exe: 0xC0000005: Access violation reading location 0x59d58d9c.
The error occurs in the QT code in the function QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e). It appears to occur at the end of the function at this line:
// deliver the event
bool consumed = receiver->event(e);
Does anyone have an idea what I am doing wrong?
-
I think we'll have to see some code (mostly from your plugin). Also when does the problem occur? Is it visible already? Another thing you could do is check the type of event (If you need help with that, just ask) in the debugger in QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e).
-
Thanks for taking a look at this. This is a pared down version of the plug-in interface class:
@
class UiPluginInterface
{
public:virtual ~UiPluginInterface(){};
virtual QStringList getWidgetNames() = 0;
virtual QWidget *createUiWidget(QWidget *parent, QString widgetName, QPoint position) = 0;
};
Q_DECLARE_INTERFACE(UiPluginInterface,INTERFACE_ID)
@Here is the widget class that is in the plugin:
@
class MyWidget : public QWidget
{
Q_OBJECTprivate:
QImage image;public:
MyWidget(QPoint position, QWidget *parent);protected:
void paintEvent(QPaintEvent * event);
};
@And here is its implementation:
@
MyWidget::MyWidget(QPoint position, QWidget *parent) : QWidget(parent)
{
QString imageFile = uiPluginsImageDir.path() + "/MyWidget.png";
image.load(imageFile);
resize(image.width(),image.height());
move(position);
}void MyWidget::paintEvent(QPaintEvent *paintEvent)
{
QPainter painter(this);
QPoint p(0,0);
painter.drawImage(p,image);
}
@I tested MyWidget by compiling into the main EXE and it works OK. It is only when I move it to the plugin that I have the problem.
The main exe loads the plugin (I have confirmed the load is successful) and calls its createUiWidget(parent, widgetName, position) function. The plugin uses "widgetName" to figure out that it needs to create a "MyWidget" and then it does this:
@
return new MyWidget(position, parent);
@The parent is a QMainWindow, but i have also tried a QGroupBox.
I put a breakpoint in the widget constructor and saw that it is executed as expected and loads the MyWidget.png file OK.
I put a breakpoint in the paintEvent and it never gets there. The widget is never displayed on the screen.
Thanks again!
EDIT: please use @-tags for code highlighting, Gerolf
-
Here is the code in the main EXE that loads the plugin and creates the widget. This code is part of the QMainWindow class. The application's QMainWindow has a button on it and the code below is executed in the button press handler slot function.
These are member variables of the QMainWindow class:
@
QPluginLoader *pluginLoader;
UiPluginInterface *uiPlugin;
@Here is the button press slot function:
@
void pluginMain::buttonPressed()
{pluginLoader = new QPluginLoader(uiPluginsDir.absoluteFilePath(fileName));
pluginLoader->load();
if(! pluginLoader->isLoaded())
{
// log an error message showing "could not load the plugin" and the file name
delete pluginLoader;
return;
}uiPlugin = qobject_cast<UiPluginInterface *>(pluginLoader->instance());
if(! uiPlugin)
{
// log an error message showing "qobject_cast failed" and the file name
delete pluginInfo;
continue;
}uiPlugin->createUiWidget(this, "myWidget", QPoint(0,0)); // "this" is a QMainWindow
return;
}
@Here is the plugin's "createUIWidget" function:
@
QWidget *UiWidgetsPlugin::createUiWidget(QWidget *parent, QString widgetName, QPoint position)
{
if(widgetName == "myWidget")
{
MyWidget *widget = new MyWidget(position, parent);
return widget;
}
return NULL;
}
@ -
I'm also getting unhandled exception in qapplication.cpp::4535
@ bool consumed = receiver->event(e);@I can reproduce this by following:
- Load Main app.
- Load plugin. (Plugin loads successfully, and I can interact with it)
- Unload plugin. (Plugin unloads successfully (I think) )
- Interact with Main app and attempt to bring one Modal dialog
- At this point I get above exception. Event type is "Event::WindowBlocked"
How did you resolve this? This is driving me crazy.
Using Qt 4.8.2 on Vista64 VS2010.
-
Hello,
I have the same problem as iunknwn and bruce.kelowna except that I get a segfault :
My application uses several similar plugins but only one can be loaded at a time (they are used to configure hardware) :
- Load Main app.
- Load plugin1 (which does not use the call to QFileDialog::getOpenFileName()
- Unload plugin1
- Load plugin2
- Call to QFileDialog::getOpenFileName()
- Segfault on qapplication.cpp::4562 :
@ // deliver the event
bool consumed = receiver->event(e);@
Also, if I switch between plugin2 and plugin3 (both use the modal dialog) : no problems.
I tried using QFileDialog::DontUseNativeDialog as I saw it mentioned somewhere, using it caused Qt to load the QFileDialog dlls (can see it happen in the debugger) but it still segfault'd. The "dll loading" does not happen if I remove the option, the application segfaults directly.
I know this thread is quite old but as it seems to be the same problem...
I am using Qt4.8.4 on W7x64.