mercredi 13 octobre 2021

No overloads function QMenuBar::addAction

I am using a lambda function to open a window. According to the documentation the QMenuBar::addAction have some overloads. documentation

But in my program i have error:

error: C2661: 'QMenuBar::addAction': no overloaded function takes 2 arguments

This place in my program:

ui->setupUi(this);
    this->setWindowTitle("Observer_demo");
    ui->menuBar->addAction("Select", [&]() {
        FormChoice* formchoice = new FormChoice;
        formchoice->setAttribute(Qt::WA_DeleteOnClose, true);
        formchoice->show();
    });

I'm using Qt 5.8.0 and my .pro file look like that:

#-------------------------------------------------
#
# Project created by QtCreator 2021-10-11T12:38:02
#
#-------------------------------------------------
CONFIG += c++11

QT       += core gui widgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = pqt_observer
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += main.cpp\
        mainwindow.cpp \
    formchoice.cpp \
    informla.cpp \
    conflicts.cpp

HEADERS  += mainwindow.h \
    formchoice.h \
    informla.h \
    conflicts.h

FORMS    += mainwindow.ui \
    formchoice.ui \
    informla.ui \
    conflicts.ui

I do not publish my code in full because my friend with an earlier version of Qt does not have an error. The function accepts both 1 and 2 and 3 arguments (according to the documentation).

Aucun commentaire:

Enregistrer un commentaire