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. Activating a Ui within an object
Forum Update on Monday, May 27th 2025

Activating a Ui within an object

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 135 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.
  • W Offline
    W Offline
    willemf
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • W willemf

      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.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      5

      • Login

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