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. QWidget: Must construct a QApplication before a QWidget

QWidget: Must construct a QApplication before a QWidget

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 6 Posters 3.8k 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.
  • michalt38M Offline
    michalt38M Offline
    michalt38
    wrote on last edited by
    #1

    Hello, I'm trying to run a QVTKOpenGLWidget in Qt5.9.2 and I'm using Visual Studio 2015 with Qt plugin. I have added folder with dll files to enviromental variable PATH and when program runs, I'm getting this error:

    QWidget: Must construct a QApplication before a QWidget
    Unhandled exception at 0x763F543B (ucrtbase.dll) in hello_test3.exe: Fatal program exit requested.

    How to deal with this?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fuel
      wrote on last edited by
      #2

      How is your main.cpp looking like?

      1 Reply Last reply
      0
      • michalt38M Offline
        michalt38M Offline
        michalt38
        wrote on last edited by
        #3

        #include "hello_test3.h"
        #include <QtWidgets/QApplication>

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        hello_test3 w;
        w.show();
        return a.exec();
        }

        jsulmJ 1 Reply Last reply
        0
        • Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @michalt38 is it possible you're mixing libraries in debug and release mode ? See this answer from stackoverflow as it might apply to your environment.

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • michalt38M michalt38

            #include "hello_test3.h"
            #include <QtWidgets/QApplication>

            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);
            hello_test3 w;
            w.show();
            return a.exec();
            }

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @michalt38 Do you have any static variables?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            michalt38M 1 Reply Last reply
            2
            • jsulmJ jsulm

              @michalt38 Do you have any static variables?

              michalt38M Offline
              michalt38M Offline
              michalt38
              wrote on last edited by
              #6

              @jsulm no, I don't

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #7

                @michalt38 said in QWidget: Must construct a QApplication before a QWidget:

                hello_test3.h

                Can you show the content of hello_test3.h and hello_test3.cpp (if it exists)?

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                2
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by dheerendra
                  #8

                  Are you creating any widget object in the global scope ? Either in some header file or somewhere else ?

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  3
                  • michalt38M Offline
                    michalt38M Offline
                    michalt38
                    wrote on last edited by
                    #9

                    This problem was beacouse I mixed debug and release libraries

                    Pablo J. RoginaP 1 Reply Last reply
                    1
                    • michalt38M michalt38

                      This problem was beacouse I mixed debug and release libraries

                      Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on last edited by
                      #10

                      @michalt38 so if your problem is solved now, please don't forget to mark your post as such.

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      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