F : QWidget: Must construct a QApplication before a QWidget
-
@rktech said in F : QWidget: Must construct a QApplication before a QWidget:
And still nothing
Not a really useful error description...
Please show us your actual, minimal code to reproduce the issue. I would guess there are more statics around...
-
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
-
@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
-
@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?
-
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 :)
-
@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.
-
@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 ? -
@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.