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. namespace problems
Forum Updated to NodeBB v4.3 + New Features

namespace problems

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 375 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.
  • grafenocarbonoG Offline
    grafenocarbonoG Offline
    grafenocarbono
    wrote on last edited by
    #1

    Hi Geeks,

    lately I have been ill-treated to easy languages (I will not name not to anger anyone) and with C++-Qt I struggle

    My problem, I think is namespace clause.

    I have a problem with my code but I I’m not able to fix.

    mainwindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QVector>
    #include "task.h"
    
    QT_BEGIN_NAMESPACE
    namespace Ui {
    class MainWindow;
    
    }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    public slots:
        void addTask();
    
    private:
        Ui::MainWindow *ui;
        QVector<Task*> mTasks;
    };
    #endif // MAINWINDOW_H
    
    

    mainwindow.cpp:

    #include "mainwindow.h"
    #include <QDebug>
    
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow),
        mTasks()
    {
        ui->setupUi(this);
        connect(ui->addTaskButton, &QPushButton::clicked, this,
                &MainWindow::addTask);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::addTask(){
        qDebug() << "User clicked";
        Task* task = new Task("Untitled task");
        mTasks.append(task);
        ui->tasksLayout->addWidget(task);
    }
    
    

    the problem is with my variable "ui" I guess is a problem of definition in namespace

    Thanks in advance

    JonBJ enjoysmathE 2 Replies Last reply
    0
    • grafenocarbonoG grafenocarbono

      Hi Geeks,

      lately I have been ill-treated to easy languages (I will not name not to anger anyone) and with C++-Qt I struggle

      My problem, I think is namespace clause.

      I have a problem with my code but I I’m not able to fix.

      mainwindow.h:

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      #include <QVector>
      #include "task.h"
      
      QT_BEGIN_NAMESPACE
      namespace Ui {
      class MainWindow;
      
      }
      QT_END_NAMESPACE
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          MainWindow(QWidget *parent = nullptr);
          ~MainWindow();
      
      public slots:
          void addTask();
      
      private:
          Ui::MainWindow *ui;
          QVector<Task*> mTasks;
      };
      #endif // MAINWINDOW_H
      
      

      mainwindow.cpp:

      #include "mainwindow.h"
      #include <QDebug>
      
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow),
          mTasks()
      {
          ui->setupUi(this);
          connect(ui->addTaskButton, &QPushButton::clicked, this,
                  &MainWindow::addTask);
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      void MainWindow::addTask(){
          qDebug() << "User clicked";
          Task* task = new Task("Untitled task");
          mTasks.append(task);
          ui->tasksLayout->addWidget(task);
      }
      
      

      the problem is with my variable "ui" I guess is a problem of definition in namespace

      Thanks in advance

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @grafenocarbono
      What line do you get what error message on?

      If you are using ui, that normally comes from using Designer to create a form. That produces a ui_....h file at build time, and Creator puts a #include "ui_....h" statement in your .cpp, but I do not see that?

      1 Reply Last reply
      3
      • grafenocarbonoG grafenocarbono

        Hi Geeks,

        lately I have been ill-treated to easy languages (I will not name not to anger anyone) and with C++-Qt I struggle

        My problem, I think is namespace clause.

        I have a problem with my code but I I’m not able to fix.

        mainwindow.h:

        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H
        
        #include <QMainWindow>
        #include <QVector>
        #include "task.h"
        
        QT_BEGIN_NAMESPACE
        namespace Ui {
        class MainWindow;
        
        }
        QT_END_NAMESPACE
        
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
        
        public:
            MainWindow(QWidget *parent = nullptr);
            ~MainWindow();
        
        public slots:
            void addTask();
        
        private:
            Ui::MainWindow *ui;
            QVector<Task*> mTasks;
        };
        #endif // MAINWINDOW_H
        
        

        mainwindow.cpp:

        #include "mainwindow.h"
        #include <QDebug>
        
        
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow),
            mTasks()
        {
            ui->setupUi(this);
            connect(ui->addTaskButton, &QPushButton::clicked, this,
                    &MainWindow::addTask);
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        void MainWindow::addTask(){
            qDebug() << "User clicked";
            Task* task = new Task("Untitled task");
            mTasks.append(task);
            ui->tasksLayout->addWidget(task);
        }
        
        

        the problem is with my variable "ui" I guess is a problem of definition in namespace

        Thanks in advance

        enjoysmathE Offline
        enjoysmathE Offline
        enjoysmath
        wrote on last edited by enjoysmath
        #3

        @grafenocarbono

        I've noticed an issue / bug with the Class wizard in Qt Creator / Designer / VS tools for Qt. Basically there's two options: include the MainWindow's auto-generated UI code as a base class and as a member (it's an option in the Class wizard dialog as you create the class).

        Forgot which one worked for me, but try both, one of them will work!

        Also, please refrain from the name-calling. We are all muscle men with a moderate enjoyment of the pleasures of geekdom. J/k, I thought it was funny 😂

        https://github.com/enjoysmath
        https://math.stackexchange.com/users/26327/exercisingmathematician

        1 Reply Last reply
        0

        • Login

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