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 ?
QtWS25 Last Chance

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.1k Views
  • 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 last edited by
    #1

    Hi, I am using QT Creator 4.6.1 based on QT 5.10.1 with OpenCV 2.4.13.

    I created a C++ console application. The contents of the main() file look something like this:

    #include <QCoreApplication>
    
    **Include OpenCV libraries here**
    
    using namespace cv;
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        Mat image;
    
        **Read in an image using imread()**
    
        imshow("Frame", image);
        waitKey(10);
    
        return a.exec();
    }
    

    However when I run the application, I get the the following error:

    QWidget: Cannot create a QWidget without QApplication

    This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

    Is there any way to fix this ? Thanks

    jsulmJ kshegunovK JonBJ 3 Replies Last reply
    0
    • R R-P-H

      Hi, I am using QT Creator 4.6.1 based on QT 5.10.1 with OpenCV 2.4.13.

      I created a C++ console application. The contents of the main() file look something like this:

      #include <QCoreApplication>
      
      **Include OpenCV libraries here**
      
      using namespace cv;
      using namespace std;
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          Mat image;
      
          **Read in an image using imread()**
      
          imshow("Frame", image);
          waitKey(10);
      
          return a.exec();
      }
      

      However when I run the application, I get the the following error:

      QWidget: Cannot create a QWidget without QApplication

      This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

      Is there any way to fix this ? Thanks

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • R R-P-H

        Hi, I am using QT Creator 4.6.1 based on QT 5.10.1 with OpenCV 2.4.13.

        I created a C++ console application. The contents of the main() file look something like this:

        #include <QCoreApplication>
        
        **Include OpenCV libraries here**
        
        using namespace cv;
        using namespace std;
        
        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
        
            Mat image;
        
            **Read in an image using imread()**
        
            imshow("Frame", image);
            waitKey(10);
        
            return a.exec();
        }
        

        However when I run the application, I get the the following error:

        QWidget: Cannot create a QWidget without QApplication

        This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

        Is there any way to fix this ? Thanks

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

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

        This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

        Assuming opencv uses the Qt backend then you have depended on an undocumented behavior. Fixing your code would be a place to start - use QApplication.

        Read and abide by the Qt Code of Conduct

        R 1 Reply Last reply
        1
        • kshegunovK kshegunov

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

          This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

          Assuming opencv uses the Qt backend then you have depended on an undocumented behavior. Fixing your code would be a place to start - use QApplication.

          R Offline
          R Offline
          R-P-H
          wrote on last edited by
          #4

          @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 ?:

          This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

          Assuming opencv uses the Qt backend then you have depended on an undocumented behavior. Fixing your code would be a place to start - use QApplication.

          QApplication only works with a GUI project.

          W kshegunovK 2 Replies Last reply
          1
          • R R-P-H

            Hi, I am using QT Creator 4.6.1 based on QT 5.10.1 with OpenCV 2.4.13.

            I created a C++ console application. The contents of the main() file look something like this:

            #include <QCoreApplication>
            
            **Include OpenCV libraries here**
            
            using namespace cv;
            using namespace std;
            
            int main(int argc, char *argv[])
            {
                QCoreApplication a(argc, argv);
            
                Mat image;
            
                **Read in an image using imread()**
            
                imshow("Frame", image);
                waitKey(10);
            
                return a.exec();
            }
            

            However when I run the application, I get the the following error:

            QWidget: Cannot create a QWidget without QApplication

            This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

            Is there any way to fix this ? Thanks

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @R-P-H

            This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

            Updating to Qt 5.10.1 from what version? Qt 4?

            R 1 Reply Last reply
            0
            • JonBJ JonB

              @R-P-H

              This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

              Updating to Qt 5.10.1 from what version? Qt 4?

              R Offline
              R Offline
              R-P-H
              wrote on last edited by
              #6

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

              @R-P-H

              This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

              Updating to Qt 5.10.1 from what version? Qt 4?

              No, Qt5, just a minor update. Other than an update, I can't imagine what could have caused this issue. It was definitely working at one stage.

              mranger90M 1 Reply Last reply
              0
              • R R-P-H

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

                @R-P-H

                This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

                Updating to Qt 5.10.1 from what version? Qt 4?

                No, Qt5, just a minor update. Other than an update, I can't imagine what could have caused this issue. It was definitely working at one stage.

                mranger90M Offline
                mranger90M Offline
                mranger90
                wrote on last edited by
                #7

                @R-P-H
                Did you change compilers as well ?

                R 1 Reply Last reply
                0
                • mranger90M mranger90

                  @R-P-H
                  Did you change compilers as well ?

                  R Offline
                  R Offline
                  R-P-H
                  wrote on last edited by
                  #8

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

                  @R-P-H
                  Did you change compilers as well ?

                  I did add a x64 bit mingw compiler to Qt. However, I did not change the compiler of the project. It is still using the default mingw32 compiler.

                  1 Reply Last reply
                  0
                  • R R-P-H

                    @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 ?:

                    This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

                    Assuming opencv uses the Qt backend then you have depended on an undocumented behavior. Fixing your code would be a place to start - use QApplication.

                    QApplication only works with a GUI project.

                    W Offline
                    W Offline
                    wrosecrans
                    wrote on last edited by
                    #9

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

                    QApplication only works with a GUI project.

                    If you want to show a GUI window, you are making a GUI project, surely?

                    R 1 Reply Last reply
                    0
                    • W wrosecrans

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

                      QApplication only works with a GUI project.

                      If you want to show a GUI window, you are making a GUI project, surely?

                      R Offline
                      R Offline
                      R-P-H
                      wrote on last edited by
                      #10

                      @wrosecrans 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 ?:

                      QApplication only works with a GUI project.

                      If you want to show a GUI window, you are making a GUI project, surely?

                      No, it's a console project. I just wanted a pop up window for test purposes. For example, to check if an image is loading correctly. As I said, it did work before. I can't say for sure what caused it to stop working.

                      1 Reply Last reply
                      0
                      • R R-P-H

                        @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 ?:

                        This problem only occured after updating QT. Previously I was able to use imshow() inside of a console application without any errors.

                        Assuming opencv uses the Qt backend then you have depended on an undocumented behavior. Fixing your code would be a place to start - use QApplication.

                        QApplication only works with a GUI project.

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #11

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

                        QApplication only works with a GUI project.

                        I'll bite. How are windows supposed to be created if you're not running X?

                        Read and abide by the Qt Code of Conduct

                        R 1 Reply Last reply
                        0
                        • kshegunovK kshegunov

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

                          QApplication only works with a GUI project.

                          I'll bite. How are windows supposed to be created if you're not running X?

                          R Offline
                          R Offline
                          R-P-H
                          wrote on last edited by
                          #12

                          @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 ?:

                          QApplication only works with a GUI project.

                          I'll bite. How are windows supposed to be created if you're not running X?

                          Well Visual Studio has no problem doing it. I have made countless win32 console applications inside of Visual Studio (where the only output is a terminal window) and imshow() works perfectly.

                          It's not like I'm trying to open the image inside a Qt GUI window. It's an OpenCV image window that should open separately. As I said, there is no question that it was working before.

                          kshegunovK 1 Reply Last reply
                          0
                          • R R-P-H

                            @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 ?:

                            QApplication only works with a GUI project.

                            I'll bite. How are windows supposed to be created if you're not running X?

                            Well Visual Studio has no problem doing it. I have made countless win32 console applications inside of Visual Studio (where the only output is a terminal window) and imshow() works perfectly.

                            It's not like I'm trying to open the image inside a Qt GUI window. It's an OpenCV image window that should open separately. As I said, there is no question that it was working before.

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #13

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

                            It's not like I'm trying to open the image inside a Qt GUI window.

                            Well apparently you are.

                            It's an OpenCV image window that should open separately.

                            Which I suspect uses Qt as a backend and it rightfully complains.

                            As I said, there is no question that it was working before.

                            This doesn't mean anything if you don't follow the rules. QWidget goes with QApplication. To that end what's the problem of using QApplication and still use the console for input and output?

                            Read and abide by the Qt Code of Conduct

                            R 1 Reply Last reply
                            0
                            • kshegunovK kshegunov

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

                              It's not like I'm trying to open the image inside a Qt GUI window.

                              Well apparently you are.

                              It's an OpenCV image window that should open separately.

                              Which I suspect uses Qt as a backend and it rightfully complains.

                              As I said, there is no question that it was working before.

                              This doesn't mean anything if you don't follow the rules. QWidget goes with QApplication. To that end what's the problem of using QApplication and still use the console for input and output?

                              R Offline
                              R Offline
                              R-P-H
                              wrote on last edited by
                              #14

                              @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's not like I'm trying to open the image inside a Qt GUI window.

                              Well apparently you are.

                              It's an OpenCV image window that should open separately.

                              Which I suspect uses Qt as a backend and it rightfully complains.

                              As I said, there is no question that it was working before.

                              This doesn't mean anything if you don't follow the rules. QWidget goes with QApplication. To that end what's the problem of using QApplication and still use the console for input and output?

                              The traditional terminal window is suppressed when using a GUI project and I have no need for a GUI window of any kind which gets created by default.

                              kshegunovK 1 Reply Last reply
                              0
                              • mranger90M Offline
                                mranger90M Offline
                                mranger90
                                wrote on last edited by mranger90
                                #15

                                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.

                                using namespace cv;
                                using namespace std;
                                
                                int main(int argc, char *argv[])
                                {
                                    QCoreApplication a(argc, argv);
                                
                                    Mat image;
                                
                                    image = imread("c:\\tmp\\triangle_red.png", CV_LOAD_IMAGE_COLOR);
                                    imshow("Frame", image);
                                
                                    return a.exec();
                                }
                                
                                R 1 Reply Last reply
                                0
                                • R R-P-H

                                  @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's not like I'm trying to open the image inside a Qt GUI window.

                                  Well apparently you are.

                                  It's an OpenCV image window that should open separately.

                                  Which I suspect uses Qt as a backend and it rightfully complains.

                                  As I said, there is no question that it was working before.

                                  This doesn't mean anything if you don't follow the rules. QWidget goes with QApplication. To that end what's the problem of using QApplication and still use the console for input and output?

                                  The traditional terminal window is suppressed when using a GUI project and I have no need for a GUI window of any kind which gets created by default.

                                  kshegunovK Offline
                                  kshegunovK Offline
                                  kshegunov
                                  Moderators
                                  wrote on last edited by
                                  #16

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

                                  The traditional terminal window is suppressed when using a GUI project and I have no need for a GUI window of any kind which gets created by default.

                                  I didn't say to change your project type. I just said to replace QCoreApplication with QApplication.

                                  Read and abide by the Qt Code of Conduct

                                  R 1 Reply Last reply
                                  0
                                  • mranger90M mranger90

                                    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.

                                    using namespace cv;
                                    using namespace std;
                                    
                                    int main(int argc, char *argv[])
                                    {
                                        QCoreApplication a(argc, argv);
                                    
                                        Mat image;
                                    
                                        image = imread("c:\\tmp\\triangle_red.png", CV_LOAD_IMAGE_COLOR);
                                        imshow("Frame", image);
                                    
                                        return a.exec();
                                    }
                                    
                                    R Offline
                                    R Offline
                                    R-P-H
                                    wrote on last edited by
                                    #17

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

                                    using namespace cv;
                                    using namespace std;
                                    
                                    int main(int argc, char *argv[])
                                    {
                                        QCoreApplication a(argc, argv);
                                    
                                        Mat image;
                                    
                                        image = imread("c:\\tmp\\triangle_red.png", CV_LOAD_IMAGE_COLOR);
                                        imshow("Frame", image);
                                    
                                        return a.exec();
                                    }
                                    

                                    Thanks for confirming. As I suspected, there is some other underlying problem on my system. Either from an update or from adding a 2nd compiler kit.

                                    1 Reply Last reply
                                    0
                                    • kshegunovK kshegunov

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

                                      The traditional terminal window is suppressed when using a GUI project and I have no need for a GUI window of any kind which gets created by default.

                                      I didn't say to change your project type. I just said to replace QCoreApplication with QApplication.

                                      R Offline
                                      R Offline
                                      R-P-H
                                      wrote on last edited by
                                      #18

                                      @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 ?:

                                      The traditional terminal window is suppressed when using a GUI project and I have no need for a GUI window of any kind which gets created by default.

                                      I didn't say to change your project type. I just said to replace QCoreApplication with QApplication.

                                      Sorry, I didn't realise you meant just changing that. Changing it gives the error that it's not found.

                                      kshegunovK 1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

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

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

                                        R 1 Reply Last reply
                                        2
                                        • R R-P-H

                                          @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 ?:

                                          The traditional terminal window is suppressed when using a GUI project and I have no need for a GUI window of any kind which gets created by default.

                                          I didn't say to change your project type. I just said to replace QCoreApplication with QApplication.

                                          Sorry, I didn't realise you meant just changing that. Changing it gives the error that it's not found.

                                          kshegunovK Offline
                                          kshegunovK Offline
                                          kshegunov
                                          Moderators
                                          wrote on last edited by kshegunov
                                          #20

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

                                          Read and abide by the Qt Code of Conduct

                                          1 Reply Last reply
                                          2

                                          • Login

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