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: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?
Forum Updated to NodeBB v4.3 + New Features

QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
opencvqapplicationqwidget
30 Posts 8 Posters 13.2k Views 4 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.
  • R Offline
    R Offline
    R-P-H
    wrote on 11 Jul 2018, 21:43 last edited by
    #21

    I will check the .pro file again and post back. However, I never used to modify anything in it before (besides linking the OpenCV library) and it was working fine like that at some stage.

    1 Reply Last reply
    0
    • S SGaist
      11 Jul 2018, 21:39

      You need to add QT += widgets to your .pro file to use QApplication.

      R Offline
      R Offline
      R-P-H
      wrote on 12 Jul 2018, 07:59 last edited by
      #22

      @SGaist said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

      You need to add QT += widgets to your .pro file to use QApplication.

      @kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

      @R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

      Changing it gives the error that it's not found.

      Can you show the project file (*.pro)? I suspect you did not add QT = core gui widgets to it.

      QT -= gui
      
      CONFIG += c++11 console
      CONFIG -= app_bundle
      
      QT += widgets
      
      DEFINES += QT_DEPRECATED_WARNINGS
      
      SOURCES += \
              main.cpp
      

      If I add either QT += widgets or QT = core gui widgets to the .pro file and replace QCoreApplication with QApplication it works fine. It will not work with QCoreApplication however.

      K 1 Reply Last reply 12 Jul 2018, 08:20
      0
      • R R-P-H
        12 Jul 2018, 07:59

        @SGaist said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

        You need to add QT += widgets to your .pro file to use QApplication.

        @kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

        @R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

        Changing it gives the error that it's not found.

        Can you show the project file (*.pro)? I suspect you did not add QT = core gui widgets to it.

        QT -= gui
        
        CONFIG += c++11 console
        CONFIG -= app_bundle
        
        QT += widgets
        
        DEFINES += QT_DEPRECATED_WARNINGS
        
        SOURCES += \
                main.cpp
        

        If I add either QT += widgets or QT = core gui widgets to the .pro file and replace QCoreApplication with QApplication it works fine. It will not work with QCoreApplication however.

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 12 Jul 2018, 08:20 last edited by
        #23

        @R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

        It will not work with QCoreApplication however.

        QCoreApplication does not perform the needed steps to initialize the runtime for creating widgets. So yes it shouldn't be possible to create widgets with QCoreApplication; if it is, then you're using an undocumented behavior that's internal to the library, and it can stop working at any time without warning or crash. Warnings from the Qt library should be treated as errors in the user code.

        Read and abide by the Qt Code of Conduct

        R 1 Reply Last reply 12 Jul 2018, 08:49
        0
        • K kshegunov
          12 Jul 2018, 08:20

          @R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

          It will not work with QCoreApplication however.

          QCoreApplication does not perform the needed steps to initialize the runtime for creating widgets. So yes it shouldn't be possible to create widgets with QCoreApplication; if it is, then you're using an undocumented behavior that's internal to the library, and it can stop working at any time without warning or crash. Warnings from the Qt library should be treated as errors in the user code.

          R Offline
          R Offline
          R-P-H
          wrote on 12 Jul 2018, 08:49 last edited by
          #24

          @kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

          @R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

          It will not work with QCoreApplication however.

          QCoreApplication does not perform the needed steps to initialize the runtime for creating widgets. So yes it shouldn't be possible to create widgets with QCoreApplication; if it is, then you're using an undocumented behavior that's internal to the library, and it can stop working at any time without warning or crash. Warnings from the Qt library should be treated as errors in the user code.

          Alright thanks, at least I know how to get it to work now although I still find it strange that it was working before without having to use QApplication.

          In terms of using QCoreApplication I was referring to @mranger90 post below:

          @mranger90 said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

          I've just confirmed that this will work on my system, Qt 5.10.0, MSVC 2017, OpenCV 3.1.0 (?), so it's not a matter of QCoreApplication vs QApplication.

          where he confirmed that it does work with QCoreApplication. Strange.

          S 1 Reply Last reply 12 Jul 2018, 08:51
          0
          • R R-P-H
            12 Jul 2018, 08:49

            @kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

            @R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

            It will not work with QCoreApplication however.

            QCoreApplication does not perform the needed steps to initialize the runtime for creating widgets. So yes it shouldn't be possible to create widgets with QCoreApplication; if it is, then you're using an undocumented behavior that's internal to the library, and it can stop working at any time without warning or crash. Warnings from the Qt library should be treated as errors in the user code.

            Alright thanks, at least I know how to get it to work now although I still find it strange that it was working before without having to use QApplication.

            In terms of using QCoreApplication I was referring to @mranger90 post below:

            @mranger90 said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

            I've just confirmed that this will work on my system, Qt 5.10.0, MSVC 2017, OpenCV 3.1.0 (?), so it's not a matter of QCoreApplication vs QApplication.

            where he confirmed that it does work with QCoreApplication. Strange.

            S Offline
            S Offline
            sierdzio
            Moderators
            wrote on 12 Jul 2018, 08:51 last edited by sierdzio 7 Dec 2018, 08:51
            #25

            @R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

            Alright thanks, at least I know how to get it to work now although I still find it strange that it was working before without having to use QApplication.

            You may want to rise this issue with OpenCV developers - looks like it is some change on their side. The documentation for imshow() does not mention any GUI config requirements.

            And if it worked before it may be a regression.

            (Z(:^

            K 1 Reply Last reply 12 Jul 2018, 08:58
            0
            • S sierdzio
              12 Jul 2018, 08:51

              @R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

              Alright thanks, at least I know how to get it to work now although I still find it strange that it was working before without having to use QApplication.

              You may want to rise this issue with OpenCV developers - looks like it is some change on their side. The documentation for imshow() does not mention any GUI config requirements.

              And if it worked before it may be a regression.

              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 12 Jul 2018, 08:58 last edited by kshegunov 7 Dec 2018, 09:19
              #26

              @sierdzio said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

              The documentation for imshow() does not mention any GUI config requirements.

              It mentions that opencv will have a backend, and this is specified when building as well (--with-qt option), thus Qt requirements propagate through to opencv.

              And if it worked before it may be a regression.

              I doubt it. I continue to claim that creating a widget, which is what apparently imshow does, is not supported with QCoreApplication, never was and never will, regardless of whether it worked before, now or in the future.

              where he confirmed that it does work with QCoreApplication.

              Before applying the patch update 5.10.1.

              Read and abide by the Qt Code of Conduct

              S 1 Reply Last reply 12 Jul 2018, 09:06
              0
              • K kshegunov
                12 Jul 2018, 08:58

                @sierdzio said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

                The documentation for imshow() does not mention any GUI config requirements.

                It mentions that opencv will have a backend, and this is specified when building as well (--with-qt option), thus Qt requirements propagate through to opencv.

                And if it worked before it may be a regression.

                I doubt it. I continue to claim that creating a widget, which is what apparently imshow does, is not supported with QCoreApplication, never was and never will, regardless of whether it worked before, now or in the future.

                where he confirmed that it does work with QCoreApplication.

                Before applying the patch update 5.10.1.

                S Offline
                S Offline
                sierdzio
                Moderators
                wrote on 12 Jul 2018, 09:06 last edited by
                #27

                @kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

                It mentions that opencv will have a backend, and this is specified when building as well (--with-qt option), thus Qt requirements propagate through to opencv.

                Is Qt the only supported backend? If yes, then indeed requirements do propagate. If no, then it may be the case that OP is using Qt for his console app, but OpenCV uses other framework to construct the window.

                Anyway, I don't know OpenCV so I'm only speculating.

                (Z(:^

                K S 2 Replies Last reply 12 Jul 2018, 09:08
                0
                • S sierdzio
                  12 Jul 2018, 09:06

                  @kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

                  It mentions that opencv will have a backend, and this is specified when building as well (--with-qt option), thus Qt requirements propagate through to opencv.

                  Is Qt the only supported backend? If yes, then indeed requirements do propagate. If no, then it may be the case that OP is using Qt for his console app, but OpenCV uses other framework to construct the window.

                  Anyway, I don't know OpenCV so I'm only speculating.

                  K Offline
                  K Offline
                  kshegunov
                  Moderators
                  wrote on 12 Jul 2018, 09:08 last edited by
                  #28

                  @sierdzio said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

                  Is Qt the only supported backend?

                  This I don't know, I don't know or use opencv as well. To be honest OpenCV's documentation's a bit vague and somewhat suspicious on the matter.

                  OpenCV uses other framework to construct the window.

                  This conflicts with the code snippet and the runtime error the OP gets ... and the fix. Apparently opencv in that case uses Qt to create the widget for display.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sierdzio
                    Moderators
                    wrote on 12 Jul 2018, 09:10 last edited by
                    #29

                    Yep, you're right.

                    (Z(:^

                    1 Reply Last reply
                    0
                    • S sierdzio
                      12 Jul 2018, 09:06

                      @kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

                      It mentions that opencv will have a backend, and this is specified when building as well (--with-qt option), thus Qt requirements propagate through to opencv.

                      Is Qt the only supported backend? If yes, then indeed requirements do propagate. If no, then it may be the case that OP is using Qt for his console app, but OpenCV uses other framework to construct the window.

                      Anyway, I don't know OpenCV so I'm only speculating.

                      S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 12 Jul 2018, 09:15 last edited by
                      #30

                      @sierdzio said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:

                      Is Qt the only supported backend? If yes, then indeed requirements do propagate.

                      No, it has been added later on. It's maybe even the latest that has been implemented.

                      AFAIK, what the OP is hitting here, is that OpenCV doesn't have an implementation for imgshow for iOS. It would require to either use Qt to show the result of what he's doing or native stuff.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      21/30

                      11 Jul 2018, 21:43

                      • Login

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