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



  • 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?



  • 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{};



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

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

  • Lifetime Qt Champion

    Hi,

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



  • 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
    

  • Qt Champions 2017

    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


  • Lifetime Qt Champion

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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.