Unsolved Activating a Ui within an object
-
I am attempting to activate a QDialog from within an object but get a message as follows:
"error: ‘DivelistGPS’ in namespace ‘Ui’ does not name a type Ui::DivelistGPS ui;
After stripping down the code and still compiling with the error, here is the header file:
#ifndef DIVELIST_GPS_H #define DIVELIST_GPS__H //namespace Ui { // class DivelistGPS; //}; class DivelistGPS : public QDialog { Q_OBJECT public: explicit DivelistGPS(QWidget *parent, QString fileName); void print(); private slots: private: Ui::DivelistGPS ui; QString fileName; }; #endif
Here is the .cpp file:
#include "ui_divelistgps.h" #include "desktop-widgets/divelistgps.h" #include <QFileDialog> #include <QProcess> #include <QMessageBox> #include <stdlib.h> #include <stdio.h> DivelistGPS::DivelistGPS(QWidget *parent, QString fileName, ui(new Ui::TabDiveInformation()) : QDialog(parent), fileName(fileName) { ui.setupUi(this); } void DivelistGPS::print() { fprintf(stderr,"Success in accessing print method\n"); }
Here are the first few lines of the .ui file:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>DivelistGPS</class> <widget class="QDialog" name="DivelistGPS"> <property name="windowModality"> <enum>Qt::WindowModal</enum>
If I activate the namespace statement in the header, it errors due to a forward declaration. I have no idea of what to do about this and would appreciate anyone else's comments.
-
@willemf said in Activating a Ui within an object:
//namespace Ui {
// class DivelistGPS;
//};" it errors due to a forward declaration" - because ui is not a pointer!
Forward declaration only works for pointers, if it is not a pointer compiler needs to know what DivelistGPS exactly is (you would need to include the header file).
So change to:Ui::DivelistGPS *ui;