Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unhandled exception sending event to qwidget in DLL
Qt 6.11 is out! See what's new in the release blog

Unhandled exception sending event to qwidget in DLL

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 5.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bruce.kelowna
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

      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).

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bruce.kelowna
        wrote on last edited by
        #3

        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_OBJECT

        private:
        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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          So,

          I assume that looking at the code that intatiates the üplugin, displays it etc would help finding the problem.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bruce.kelowna
            wrote on last edited by
            #5

            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;
            }
            @

            1 Reply Last reply
            0
            • I Offline
              I Offline
              iunknwn
              wrote on last edited by
              #6

              I'm also getting unhandled exception in qapplication.cpp::4535
              @ bool consumed = receiver->event(e);@

              I can reproduce this by following:

              1. Load Main app.
              2. Load plugin. (Plugin loads successfully, and I can interact with it)
              3. Unload plugin. (Plugin unloads successfully (I think) )
              4. Interact with Main app and attempt to bring one Modal dialog
              5. 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.

              Vista x64 with Qt 4.8.2 and VS2010

              1 Reply Last reply
              0
              • E Offline
                E Offline
                eMixam
                wrote on last edited by
                #7

                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) :

                1. Load Main app.
                2. Load plugin1 (which does not use the call to QFileDialog::getOpenFileName()
                3. Unload plugin1
                4. Load plugin2
                5. Call to QFileDialog::getOpenFileName()
                6. 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.

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  eMixam
                  wrote on last edited by
                  #8

                  Does anybody have a clue about this issue ?

                  I'm afraid I'll have to use some workaround, like blocking the application on one particular type of plugins once the user loaded one corresponding to this type...

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    eMixam
                    wrote on last edited by
                    #9

                    I tried to change the location of the call to QFileDialog::getOpenFileName from the plugin to the main application, but I get the same segfault.

                    EDIT : Also tried with the non-static version (fileDialog.exec()) and... nothing, segfault again.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved