Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    4
    8
    1498
    Loading More Posts
    • 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
      t0msk last edited by

      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++

      V 1 Reply Last reply Reply Quote 0
      • V
        VRonin @t0msk last edited by

        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 Reply Quote 3
        • T
          t0msk @VRonin last edited by t0msk

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • T
              t0msk last edited by

              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_1980 1 Reply Last reply Reply Quote 0
              • aha_1980
                aha_1980 Lifetime Qt Champion @t0msk last edited by

                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 Reply Quote 3
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  @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 Reply Quote 4
                  • T
                    t0msk @aha_1980 last edited by t0msk

                    @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 Reply Quote 1
                    • First post
                      Last post