PDA

View Full Version : i still get buggered: lineEdit problems



Petr_Kropotkin
30th January 2010, 22:36
I am writinga palindrome checker widget.
I get one error:
pallindrome.cpp:37: error: 'lineEdit' was not declared in this scope
Here is the code for the main method


void palindrome::check_palindrome()
{
int rem,rem2,rem3,rem4,digit;
int place1,place2,place3,place4,place5;

QMessageBox msgbox;

digit=lineEdit.text();
rem= digit % 10000;
place1= (digit-rem)/10000;
rem2= rem % 1000;
place2= (rem-rem2)/1000;
rem3 = rem2 % 100;
place3= (rem2-rem3)/100;
rem4 = rem3 % 10;
place4= (rem3-rem4)/10;
place5=digit-(10000*place1+1000*place2+100*place3+10*place4);
if((place1==place5)&&(place2==place4))
{
msgbox.setText("number s a palindrome");
msgbox.exec();
}


I put the line lineEdit->text() in the UI file so I don't know why it is giving me this error.
I am followoing a similar logic to the last prolblem. The only thing that I might need to do is convert the
lineEdit to a number , if it isn't already done.

norobro
31st January 2010, 03:25
Really need to see the rest of your code to give a definitive answer.

If you added a QLineEdit named lineEdit to your form using QtDesigner the code in your function would need to be:
digit=QString::number(lineEdit->text());

There is no need to add anything to your UI file. Note the comment at the top of the file. If you make changes to your form with the designer the file is regenerated and all changes are lost so you would have to re-add any changes that you make.

Petr_Kropotkin
31st January 2010, 05:10
I ge the following error:
palindrome.cpp:31: error: 'lineEdit' was not declared in this scope

If I add code to the UI, I generate the file and add it in.

Here is palindrome.cpp


#include "palindrome.h"
#include "ui_palindrome.h"
#include "QtGui"
palindrome::palindrome(QWidget *parent) :
QDialog(parent),
ui(new Ui::palindrome)
{
ui->setupUi(this);
}

palindrome::~palindrome()
{
delete ui;
}

void palindrome::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}

void palindrome::check_palindrome()
{
int digit;
QMessageBox msgbox;
digit=QString::number(lineEdit->text());

rem= digit % 10000;
place1= (digit-rem)/10000;
rem2= rem % 1000;
place2= (rem-rem2)/1000;
rem3 = rem2 % 100;
place3= (rem2-rem3)/100;
rem4 = rem3 % 10;
place4= (rem3-rem4)/10;
place5=digit-(10000*place1+1000*place2+100*place3+10*place4);
if((place1==place5) && (place2==place4))
{
{msgbox.setText(" number is a palindrome");
msgbox.exec();
}

norobro
31st January 2010, 05:23
Please post ui_palindrome.h

franz
31st January 2010, 09:07
It should probably be


digit=QString::number(ui->lineEdit->text());

Petr_Kropotkin
31st January 2010, 15:22
nope that don't work .
The following erros pop up:
palindrome.cpp: In member function 'void palindrome::palindrome_checker()':
palindrome.cpp:26: error: no matching function for call to 'QString::number(QString)'
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:389: note: candidates are: static QString QString::number(int, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:390: note: static QString QString::number(uint, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:391: note: static QString QString::number(long int, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:392: note: static QString QString::number(ulong, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:393: note: static QString QString::number(qlonglong, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:394: note: static QString QString::number(qulonglong, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:395: note: static QString QString::number(double, char, int)

Petr_Kropotkin
31st January 2010, 15:27
Here is ui_palindrome



/************************************************** ******************************
** Form generated from reading UI file 'palindrome.ui'
**
** Created: Sun Jan 31 08:18:02 2010
** by: Qt User Interface Compiler version 4.6.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
************************************************** ******************************/

#ifndef UI_PALINDROME_H
#define UI_PALINDROME_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QGroupBox>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>

QT_BEGIN_NAMESPACE

class Ui_palindrome
{
public:
QGroupBox *groupBox;
QLabel *label;
QLineEdit *lineEdit;
QPushButton *checkButton;
QPushButton *pushButton_2;

void setupUi(QDialog *palindrome)
{
if (palindrome->objectName().isEmpty())
palindrome->setObjectName(QString::fromUtf8("palindrome"));
palindrome->resize(393, 95);
groupBox = new QGroupBox(palindrome);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
groupBox->setGeometry(QRect(20, 10, 271, 80));
label = new QLabel(groupBox);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(10, 30, 141, 16));
lineEdit = new QLineEdit(groupBox);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(150, 30, 113, 20));
lineEdit->text();
checkButton = new QPushButton(palindrome);
checkButton->setObjectName(QString::fromUtf8("checkButton"));
checkButton->setGeometry(QRect(310, 10, 75, 23));
pushButton_2 = new QPushButton(palindrome);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
pushButton_2->setGeometry(QRect(310, 50, 75, 23));

retranslateUi(palindrome);
QObject::connect(pushButton_2, SIGNAL(clicked(bool)), palindrome, SLOT(close()));
QObject::connect(checkButton, SIGNAL(clicked(bool)), lineEdit, SLOT(copy()));

QMetaObject::connectSlotsByName(palindrome);
} // setupUi

void retranslateUi(QDialog *palindrome)
{
palindrome->setWindowTitle(QApplication::translate("palindrome", "palindrome", 0, QApplication::UnicodeUTF8));
groupBox->setTitle(QApplication::translate("palindrome", "Palindrome Entry Box", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("palindrome", "Enter number to be checked:", 0, QApplication::UnicodeUTF8));
checkButton->setText(QApplication::translate("palindrome", "Check", 0, QApplication::UnicodeUTF8));
pushButton_2->setText(QApplication::translate("palindrome", "Cancel", 0, QApplication::UnicodeUTF8));
} // retranslateUi

};

namespace Ui {
class palindrome: public Ui_palindrome {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_PALINDROME_H

franz
31st January 2010, 15:46
The following erros pop up:
palindrome.cpp: In member function 'void palindrome::palindrome_checker()':
palindrome.cpp:26: error: no matching function for call to 'QString::number(QString)'
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:389: note: candidates are: static QString QString::number(int, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:390: note: static QString QString::number(uint, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:391: note: static QString QString::number(long int, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:392: note: static QString QString::number(ulong, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:393: note: static QString QString::number(qlonglong, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:394: note: static QString QString::number(qulonglong, int)
c:\Qt\qt\include/QtCore/../../src/corelib/tools/qstring.h:395: note: static QString QString::number(double, char, int)

That's a diifferent error (I should have spotted that one). You might have noticed that the lineEdit variable was actually found. The QString::number() function converts a number into a string, not the other way around. The correct line would be

digit=ui->lineEdit->text().toInt();
See the QString docs for more.

Petr_Kropotkin
31st January 2010, 15:56
Nope that doesn't work
I get the following errors after cleaning and building:

palindrome.cpp: In member function 'void palindrome:: palindrome_checker()':
palindrome.cpp:26: error: 'lineEdit' was not declared in this scope

franz
31st January 2010, 16:00
Don't forget to add the ui-> in front of lineEdit.

Petr_Kropotkin
31st January 2010, 16:19
That works . Thanks.