Important: Please read the Qt Code of Conduct -

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 *>( {
            MainWindow w();
    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


    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 ( {
            QCryptographicHash hash(hashAlgorithm);
            if (hash.addData(&f)) {
                return hash.result();
        return QByteArray();
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        delete ui;
    void MainWindow::on_actionAbout_triggered()
        About about;
    void MainWindow::on_actionSettings_triggered()
        Settings settings;


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

  • Lifetime Qt Champion

    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.


  • 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