Non-static data member warnings [SOLVED]
-
hello,
I'm running into an abundant amount of non-static warnings for the way I'm setting up my layouts and buttons. The Project still works fine warnings and all.
class Calibration : public QObject { Q_OBJECT public: explicit Calibration(QObject *parent = 0); public: QHBoxLayout *MainLayout = new QHBoxLayout; QTableWidget *table = new QTableWidget; QHBoxLayout *TableLayout = new QHBoxLayout; QVBoxLayout *buttonlayout= new QVBoxLayout; QPushButton *CalPA = new QPushButton("Save Cal"); QPushButton *GetPA = new QPushButton("Get Cal"); QPushButton *SaveFile = new QPushButton("Save to File"); QPushButton *GetFile = new QPushButton("Recall File"); private: QStringList m2_TableHeader; signals: public slots: };
if I change everything to
QHBoxLayout *MainLayout; QTableWidget *table; QHBoxLayout *TableLayout; QVBoxLayout *buttonlayout; QPushButton *CalPA; QPushButton *GetPA; QPushButton *SaveFile; QPushButton *GetFile ;
this makes the warnings go away but the program crashes. I know the issue is I'm declaring them publicly but I need to use them in a separate class so I don't think I can do so while declaring them privately. Should I be concerned, what should I change to fix this?
-
Hi,
That's because you're trying to do in-class initialization without C++11 activated. Since you don't seem to use C++11 you must move them in the constructor.
-
If I move them in the constructor they become static and I can't use them in my other class. The issue with that is I declare the buttons public in the header and then lay them out and show them In a separate class constructor(to make the code a little more readable). Would it be in bad taste just to leave it the way it is even if it works? Do you know of a solution where I can declare them in one constructor and use them in a completely different constructor?
-
I solved my issue. Here is the Code:
.h file
public: QVBoxLayout *buttonlayout; QPushButton *CalPA; QPushButton *GetPA; QPushButton *SaveFile; QPushButton *GetFile;
.ccp file
buttonlayout= new QVBoxLayout; CalPA = new QPushButton("Save Cal"); GetPA = new QPushButton("Get Cal"); SaveFile = new QPushButton("Save to File"); GetFile = new QPushButton("Recall File");
Works, no warnings no crashes.
-
Something sounds fishy: why are you trying to access these members from other widgets ?
-
What I actually wanted was to create and populate a tab in a UI in a separate class. then connect those buttons and what not with code in the MainWindow class. But I actually decided to move most of the initialization back over to the Mainwindow, because of issues with it correctly updating information.
-
@koahnig double check your settings, the mailing option should be there to configure it.
-
@SGaist
Apparently landed in the wrong place.
Anyway, I am typically simply checking stuff with the Alarm bell symbol in the top row.
All mailings do not help at all, because for sure I am not checking those or only occassionally at most. -
The notifications bell doesn't seem to always return the data corresponding to the number it shows