gpt4 book ai didi

c++ - 我该如何解决这个错误?

转载 作者:行者123 更新时间:2023-11-28 05:45:15 26 4
gpt4 key购买 nike

我在阅读“使用 Qt 进行 C++ GUI 编程”一书时尝试运行此示例代码时遇到了这个错误。

gotocelldialog.h :

    #ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H

#include <QDialog>
#include "ui_gotocelldialog.h"
class gotocelldialog : public QDialog, public Ui::goToCellDialog
{
Q_OBJECT
public:
explicit gotocelldialog(QWidget *parent = 0);

signals:

public slots:
void on_lineEdit_textChanged();
};

#endif // GOTOCELLDIALOG_H

gotocelldialog.cpp :

#include "gotocelldialog.h"
#include <QtGui>
gotocelldialog::gotocelldialog(QWidget *parent) :
QDialog(parent)
{
setupUi(this);
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp,this));
connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(cancelButton,SIGNAL(clicked()),this,SLOT(accept()));
}

void gotocelldialog::on_lineEdit_textChanged(){
okButton->setEnabled(lineEdit->hasAcceptableInput());
}

main.cpp :

#include <QApplication>
#include <QDialog>
#include "gotocelldialog.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

gotocelldialog* dialog = new gotocelldialog();
dialog->show();
return a.exec();
}

当我运行这个程序时,它显示这个错误信息:

/home/ayush/untitled3/gotocelldialog.cpp:6: error: no matching function for call to 'gotocelldialog::setupUi(gotocelldialog*)'
setupUi(this);
^
../untitled3/gotocelldialog.cpp:6:17: note: candidate is:
In file included from ../untitled3/gotocelldialog.h:5:0,
from ../untitled3/gotocelldialog.cpp:1:
./ui_gotocelldialog.h:49:10: note: void Ui_goToCellDialog::setupUi(QMainWindow*)
void setupUi(QMainWindow *goToCellDialog)
^
./ui_gotocelldialog.h:49:10: note: no known conversion for argument 1 from 'gotocelldialog*' to 'QMainWindow*'
Makefile:344: recipe for target 'gotocelldialog.o' failed
make: *** [gotocelldialog.o] Error 1
17:15:13: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled3 (kit: Desktop)
When executing step 'Make'

这个错误的原因是什么,如何解决?

最佳答案

看起来您的 ui 文件定义了一个 QMainWindow,但您的代码需要一个 QDialog

所以存在不匹配,您可能应该从 QDialog 模板重新创建 ui 文件,或者在编辑器中更改它。

关于c++ - 我该如何解决这个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36355605/

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