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. Member show is non-class type 'MainWindow()'

Member show is non-class type 'MainWindow()'

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 2.7k 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.
  • T Offline
    T Offline
    t0msk
    wrote on last edited by
    #1

    Hello, I would like to ask you about this error:

    error: request for member 'show' in 'w', which is of non-class type 'MainWindow()'
    

    and this is code:

    QScopedPointer<QCoreApplication> app(createApplication(argc, argv, data));
    
    if (qobject_cast<QApplication *>(app.data())) {
            MainWindow w();
            w.show();
    }
    
    return app->exec();
    

    What is wrong with it, please?

    Student who loves C/C++

    VRoninV 1 Reply Last reply
    0
    • T t0msk

      Hello, I would like to ask you about this error:

      error: request for member 'show' in 'w', which is of non-class type 'MainWindow()'
      

      and this is code:

      QScopedPointer<QCoreApplication> app(createApplication(argc, argv, data));
      
      if (qobject_cast<QApplication *>(app.data())) {
              MainWindow w();
              w.show();
      }
      
      return app->exec();
      

      What is wrong with it, please?

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      MainWindow w();

      declares a function that takes no arguments and returns a MainWindow. This is one of the ambiguities the C++11 brace constructor removed.

      Use either MainWindow w; or MainWindow w{};

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      T 1 Reply Last reply
      3
      • VRoninV VRonin

        MainWindow w();

        declares a function that takes no arguments and returns a MainWindow. This is one of the ambiguities the C++11 brace constructor removed.

        Use either MainWindow w; or MainWindow w{};

        T Offline
        T Offline
        t0msk
        wrote on last edited by t0msk
        #3

        @VRonin Thank you I changed it to MainWindow w; but there is another problem:

        error: no matching function for call to 'MainWindow::MainWindow()'
        

        Student who loves C/C++

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Can you show the header and code of your MainWindow class ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • T Offline
            T Offline
            t0msk
            wrote on last edited by
            #5

            mainwindow.cpp:

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include "about.h"
            #include "settings.h"
            
            #include "QHash"
            #include "QFile"
            #include "QCryptographicHash"
            #include "QDebug"
            
            QByteArray fileChecksum(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm)
            {
                QFile f(fileName);
            
                if (f.open(QFile::ReadOnly)) {
            
                    QCryptographicHash hash(hashAlgorithm);
            
                    if (hash.addData(&f)) {
                        return hash.result();
                    }
                }
                return QByteArray();
            }
            
            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            
            
            void MainWindow::on_actionAbout_triggered()
            {
                About about;
                about.setModal(true);
                about.exec();
            }
            
            void MainWindow::on_actionSettings_triggered()
            {
                Settings settings;
                settings.setModal(true);
                settings.exec();
            }
            

            mainwindow.h:

            #ifndef MAINWINDOW_H
            #define MAINWINDOW_H
            
            #include <QMainWindow>
            
            namespace Ui {
            class MainWindow;
            }
            
            class MainWindow : public QMainWindow
            {
                Q_OBJECT
            
            public:
                explicit MainWindow(QHash<QString, QString>, QWidget *parent = 0);
                ~MainWindow();
            
            private slots:
                void on_actionAbout_triggered();
            
                void on_actionSettings_triggered();
            
            private:
                Ui::MainWindow *ui;
            };
            
            #endif // MAINWINDOW_H
            

            Student who loves C/C++

            aha_1980A 1 Reply Last reply
            0
            • T t0msk

              mainwindow.cpp:

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              #include "about.h"
              #include "settings.h"
              
              #include "QHash"
              #include "QFile"
              #include "QCryptographicHash"
              #include "QDebug"
              
              QByteArray fileChecksum(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm)
              {
                  QFile f(fileName);
              
                  if (f.open(QFile::ReadOnly)) {
              
                      QCryptographicHash hash(hashAlgorithm);
              
                      if (hash.addData(&f)) {
                          return hash.result();
                      }
                  }
                  return QByteArray();
              }
              
              MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
              }
              
              MainWindow::~MainWindow()
              {
                  delete ui;
              }
              
              
              void MainWindow::on_actionAbout_triggered()
              {
                  About about;
                  about.setModal(true);
                  about.exec();
              }
              
              void MainWindow::on_actionSettings_triggered()
              {
                  Settings settings;
                  settings.setModal(true);
                  settings.exec();
              }
              

              mainwindow.h:

              #ifndef MAINWINDOW_H
              #define MAINWINDOW_H
              
              #include <QMainWindow>
              
              namespace Ui {
              class MainWindow;
              }
              
              class MainWindow : public QMainWindow
              {
                  Q_OBJECT
              
              public:
                  explicit MainWindow(QHash<QString, QString>, QWidget *parent = 0);
                  ~MainWindow();
              
              private slots:
                  void on_actionAbout_triggered();
              
                  void on_actionSettings_triggered();
              
              private:
                  Ui::MainWindow *ui;
              };
              
              #endif // MAINWINDOW_H
              
              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi @t0msk,

              in your header you have: explicit MainWindow(QHash<QString, QString>, QWidget *parent = 0); but in your C++ file you have: MainWindow::MainWindow(QWidget *parent).

              That does not fit, and it does especially not fit your MainWindow w; in the main.cpp file.

              Regards

              Qt has to stay free or it will die.

              T 1 Reply Last reply
              3
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @t0msk said in Member show is non-class type 'MainWindow()':

                explicit MainWindow(QHash<QString, QString>, QWidget *parent = 0);

                You have a mandatory parameter here. Since you don't provide it it can't work.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                4
                • aha_1980A aha_1980

                  Hi @t0msk,

                  in your header you have: explicit MainWindow(QHash<QString, QString>, QWidget *parent = 0); but in your C++ file you have: MainWindow::MainWindow(QWidget *parent).

                  That does not fit, and it does especially not fit your MainWindow w; in the main.cpp file.

                  Regards

                  T Offline
                  T Offline
                  t0msk
                  wrote on last edited by t0msk
                  #8

                  @aha_1980 @SGaist Ahh sorry, I forgot to remove it ^^ because I was changing code :) Thank you :)

                  Student who loves C/C++

                  1 Reply Last reply
                  1

                  • Login

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