gpt4 book ai didi

c++ - Qt 的一些问题 (C++)

转载 作者:行者123 更新时间:2023-11-28 01:04:37 25 4
gpt4 key购买 nike

主要.cpp

#include <QtGui>
#include <QApplication>


int main(int argv, char **args)
{
QApplication app(argv, args);

QTextEdit textEdit;
QPushButton quitButton("Quit");

QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));

QVBoxLayout layout;
layout.addWidget(&textEdit);
layout.addWidget(&quitButton);

QWidget window;
window.setLayout(&layout);
window.show();

return app.exec();
}

记事本.cpp

#include <QtGui>
#include <QApplication>

class Notepad : public QMainWindow
{


Notepad::Notepad()
{
saveAction = new QAction(tr("&Open"), this);
saveAction = new QAction(tr("&Save"), this);
exitAction = new QAction(tr("E&xit"), this);

connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));

fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAction);
fileMenu->addAction(saveAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);

textEdit = new QTextEdit;
setCentralWidget(textEdit);

setWindowTitle(tr("Notepad"));
}
Q_OBJECT

public:
Notepad();

private slots:
void open();
void save();
void quit();

private:
QTextEdit *textEdit;

QAction *openAction;
QAction *saveAction;
QAction *exitAction;

QMenu *fileMenu;
};

错误:

extra qualification 'NotePad::' on Member Notepad (Line 8)

notepad::notepad() cannot be overloaded (Line 32)

with notepad::notepad (line 8)

为什么会出现这些错误?构造函数看起来不错,类设置看起来也不错。但是我收到了这些错误。

最佳答案

Notepad 类中 Notepad() 构造函数前面的 Notepad:: 不是必需的。后面的声明也不是,因为您已经这样做并在上面定义了它(尽管是私下的)。您可能需要考虑将其分成头文件和 cpp 文件。

您发布的代码仍然存在各种其他问题,但您发布的错误很可能是由我上面提到的引起的。

关于c++ - Qt 的一些问题 (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6963775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com