How can I fix this error?

Saksham

I came across this error when I tried to run this example code while reading the book - "C++ GUI programming with Qt".

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();
    }

When I run this program , it displays this error message :

/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'

What is the reason for this error and how can this be solved ?

Ilya

Looks like your ui file defines a QMainWindow, but that your code expects a QDialog.

So there's a mismatch, your should probably recreate the ui file from the QDialog template, or change it in an editor.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related