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. F : QWidget: Must construct a QApplication before a QWidget
Forum Updated to NodeBB v4.3 + New Features

F : QWidget: Must construct a QApplication before a QWidget

Scheduled Pinned Locked Moved Solved General and Desktop
qt-android
21 Posts 3 Posters 4.6k 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.
  • R Offline
    R Offline
    rktech
    wrote on 25 Mar 2020, 15:51 last edited by rktech
    #12

    Changed files from begining(note, running on android, on desktop it runs correctly):
    Calculations.cpp

    #include "calculations.h"
    
    Calculations::Calculations()
    {
    
    }
    int Calculations::Percent(int source, int percent){
        return source*percent/100;
    }
    void Calculations::row(QPushButton *p, QProgressBar *b){
    QDesktopWidget dw;
    p->setGeometry(Percent(dw.width(),75),Percent(dw.height(),c),Percent(dw.width(),25),Percent(dw.height(),4));
    b->setGeometry(0,Percent(dw.height(),c),Percent(dw.width(),75),Percent(dw.height(),4));
    c+=4;
    return;
    }
    
    

    Calculations.h

    #ifndef CALCULATIONS_H
    #define CALCULATIONS_H
    #include <QApplication>
    #include <QPushButton>
    #include <QProgressBar>
    #include <QDesktopWidget>
    class Calculations
    {
    public:
        Calculations();
        static int Percent(int source, int percent);
        void row(QPushButton *p, QProgressBar *b);
    private:
        int c = 28;
       // QDesktopWidget dw;
    };
    
    #endif // CALCULATIONS_H
    
    
    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 25 Mar 2020, 15:54 last edited by
      #13

      @rktech said in F : QWidget: Must construct a QApplication before a QWidget:

      QDesktopWidget dw;

      Please read the documentation...: https://doc.qt.io/qt-5/qdesktopwidget.html#obtaining-a-desktop-widget

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply 25 Mar 2020, 16:02
      1
      • C Christian Ehrlicher
        25 Mar 2020, 15:54

        @rktech said in F : QWidget: Must construct a QApplication before a QWidget:

        QDesktopWidget dw;

        Please read the documentation...: https://doc.qt.io/qt-5/qdesktopwidget.html#obtaining-a-desktop-widget

        R Offline
        R Offline
        rktech
        wrote on 25 Mar 2020, 16:02 last edited by
        #14

        @Christian-Ehrlicher I have read it, but I can't figure how to do it better. I have only one screen on my phone. So how can I define the dw better?

        1 Reply Last reply
        0
        • C Christian Ehrlicher
          25 Mar 2020, 15:28

          @mrjj said in F : QWidget: Must construct a QApplication before a QWidget:

          Yes i agree but do you think its the reason for the "QApplication before a QWidget" ?

          It's static so it must be initialized somewhere which is executed before main, yes.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 25 Mar 2020, 16:03 last edited by mrjj
          #15

          Hi

          It's static so it must be initialized somewhere which is executed before main, yes.

          Ok. Im asking as the instance is first created in MainWindow and i cannot
          reproduce it here using a static in a class which first is instantiated after QApp in main.

          Im well aware that global/ global static is initilized before main but i did not know also it goes for
          statics inside class that is created later than QApp.

          Live and lean, i guess :)

          C R 2 Replies Last reply 25 Mar 2020, 16:06
          0
          • M mrjj
            25 Mar 2020, 16:03

            Hi

            It's static so it must be initialized somewhere which is executed before main, yes.

            Ok. Im asking as the instance is first created in MainWindow and i cannot
            reproduce it here using a static in a class which first is instantiated after QApp in main.

            Im well aware that global/ global static is initilized before main but i did not know also it goes for
            statics inside class that is created later than QApp.

            Live and lean, i guess :)

            C Online
            C Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 25 Mar 2020, 16:06 last edited by
            #16

            @mrjj I meant the static in the header in the first post - I wondered if it really linked (I would guess no since the static dw was not initialized anywhere) therefore my guess is there is more than we see here.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • M mrjj
              25 Mar 2020, 16:03

              Hi

              It's static so it must be initialized somewhere which is executed before main, yes.

              Ok. Im asking as the instance is first created in MainWindow and i cannot
              reproduce it here using a static in a class which first is instantiated after QApp in main.

              Im well aware that global/ global static is initilized before main but i did not know also it goes for
              statics inside class that is created later than QApp.

              Live and lean, i guess :)

              R Offline
              R Offline
              rktech
              wrote on 25 Mar 2020, 16:13 last edited by
              #17

              @mrjj Anything that comes to me by this? I am sorry, I am a beginner.

              M 1 Reply Last reply 25 Mar 2020, 16:21
              0
              • R rktech
                25 Mar 2020, 16:13

                @mrjj Anything that comes to me by this? I am sorry, I am a beginner.

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 25 Mar 2020, 16:21 last edited by mrjj
                #18

                @rktech
                Sorry no new ideas.

                After you removed all use of static.
                then clean the build folder (delete all files)
                so we are sure its all recompiled.
                Then rebuild all.

                If you still get that warning then there must be a static or global var in some other file not shown.

                Also using the code shown, i dont get this warning on desktop.

                But you still get it on Android but not Desktop ?
                And you are 100% sure it was totallt recompiled after you removed static ?

                When you say "And removed static from QdesktopWidget dw in .cpp"
                that was for the one inside a function, correct ?
                Not something outside class or function ?

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rktech
                  wrote on 25 Mar 2020, 16:37 last edited by
                  #19

                  Cleaned, remaked and now it worked

                  M 1 Reply Last reply 25 Mar 2020, 16:50
                  1
                  • C Online
                    C Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 25 Mar 2020, 16:38 last edited by
                    #20

                    @rktech said in F : QWidget: Must construct a QApplication before a QWidget:

                    Cleaned, remaked and now it worked

                    Then please mark this topic as solved, thx.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    1
                    • R rktech
                      25 Mar 2020, 16:37

                      Cleaned, remaked and now it worked

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 25 Mar 2020, 16:50 last edited by
                      #21

                      @rktech
                      Super. So it was the statics.
                      So i also learned something new :)

                      1 Reply Last reply
                      0

                      21/21

                      25 Mar 2020, 16:50

                      • Login

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