Results 1 to 11 of 11

Thread: i still get buggered: lineEdit problems

  1. #1
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default i still get buggered: lineEdit problems

    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
    Qt Code:
    1. void palindrome::check_palindrome()
    2. {
    3. int rem,rem2,rem3,rem4,digit;
    4. int place1,place2,place3,place4,place5;
    5.  
    6. QMessageBox msgbox;
    7.  
    8. digit=lineEdit.text();
    9. rem= digit % 10000;
    10. place1= (digit-rem)/10000;
    11. rem2= rem % 1000;
    12. place2= (rem-rem2)/1000;
    13. rem3 = rem2 % 100;
    14. place3= (rem2-rem3)/100;
    15. rem4 = rem3 % 10;
    16. place4= (rem3-rem4)/10;
    17. place5=digit-(10000*place1+1000*place2+100*place3+10*place4);
    18. if((place1==place5)&&(place2==place4))
    19. {
    20. msgbox.setText("number s a palindrome");
    21. msgbox.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: i still get buggered: lineEdit problems

    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:
    Qt Code:
    1. digit=QString::number(lineEdit->text());
    To copy to clipboard, switch view to plain text mode 

    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.

  3. #3
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i still get buggered: lineEdit problems

    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
    Qt Code:
    1. #include "palindrome.h"
    2. #include "ui_palindrome.h"
    3. #include "QtGui"
    4. palindrome::palindrome(QWidget *parent) :
    5. QDialog(parent),
    6. ui(new Ui::palindrome)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. palindrome::~palindrome()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void palindrome::changeEvent(QEvent *e)
    17. {
    18. QDialog::changeEvent(e);
    19. switch (e->type()) {
    20. case QEvent::LanguageChange:
    21. ui->retranslateUi(this);
    22. break;
    23. default:
    24. break;
    25. }
    26. }
    27.  
    28. void palindrome::check_palindrome()
    29. {
    30. int digit;
    31. QMessageBox msgbox;
    32. digit=QString::number(lineEdit->text());
    33.  
    34. rem= digit % 10000;
    35. place1= (digit-rem)/10000;
    36. rem2= rem % 1000;
    37. place2= (rem-rem2)/1000;
    38. rem3 = rem2 % 100;
    39. place3= (rem2-rem3)/100;
    40. rem4 = rem3 % 10;
    41. place4= (rem3-rem4)/10;
    42. place5=digit-(10000*place1+1000*place2+100*place3+10*place4);
    43. if((place1==place5) && (place2==place4))
    44. {
    45. {msgbox.setText(" number is a palindrome");
    46. msgbox.exec();
    47. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Petr_Kropotkin; 31st January 2010 at 04:16.

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: i still get buggered: lineEdit problems

    Please post ui_palindrome.h
    Last edited by norobro; 31st January 2010 at 04:24. Reason: changed ui. to ui_

  5. #5
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: i still get buggered: lineEdit problems

    It should probably be
    Qt Code:
    1. digit=QString::number(ui->lineEdit->text());
    To copy to clipboard, switch view to plain text mode 
    Last edited by franz; 31st January 2010 at 08:09. Reason: ui was a pointed at
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  6. #6
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i still get buggered: lineEdit problems

    nope that don't work .
    The following erros pop up:
    palindrome.cpp: In member function 'void palindrome:alindrome_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)

  7. #7
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i still get buggered: lineEdit problems

    Here is ui_palindrome

    Qt Code:
    1. /********************************************************************************
    2. ** Form generated from reading UI file 'palindrome.ui'
    3. **
    4. ** Created: Sun Jan 31 08:18:02 2010
    5. ** by: Qt User Interface Compiler version 4.6.0
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling UI file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_PALINDROME_H
    11. #define UI_PALINDROME_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QDialog>
    18. #include <QtGui/QGroupBox>
    19. #include <QtGui/QHeaderView>
    20. #include <QtGui/QLabel>
    21. #include <QtGui/QLineEdit>
    22. #include <QtGui/QPushButton>
    23.  
    24. QT_BEGIN_NAMESPACE
    25.  
    26. class Ui_palindrome
    27. {
    28. public:
    29. QGroupBox *groupBox;
    30. QLabel *label;
    31. QLineEdit *lineEdit;
    32. QPushButton *checkButton;
    33. QPushButton *pushButton_2;
    34.  
    35. void setupUi(QDialog *palindrome)
    36. {
    37. if (palindrome->objectName().isEmpty())
    38. palindrome->setObjectName(QString::fromUtf8("palindrome"));
    39. palindrome->resize(393, 95);
    40. groupBox = new QGroupBox(palindrome);
    41. groupBox->setObjectName(QString::fromUtf8("groupBox"));
    42. groupBox->setGeometry(QRect(20, 10, 271, 80));
    43. label = new QLabel(groupBox);
    44. label->setObjectName(QString::fromUtf8("label"));
    45. label->setGeometry(QRect(10, 30, 141, 16));
    46. lineEdit = new QLineEdit(groupBox);
    47. lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    48. lineEdit->setGeometry(QRect(150, 30, 113, 20));
    49. lineEdit->text();
    50. checkButton = new QPushButton(palindrome);
    51. checkButton->setObjectName(QString::fromUtf8("checkButton"));
    52. checkButton->setGeometry(QRect(310, 10, 75, 23));
    53. pushButton_2 = new QPushButton(palindrome);
    54. pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
    55. pushButton_2->setGeometry(QRect(310, 50, 75, 23));
    56.  
    57. retranslateUi(palindrome);
    58. QObject::connect(pushButton_2, SIGNAL(clicked(bool)), palindrome, SLOT(close()));
    59. QObject::connect(checkButton, SIGNAL(clicked(bool)), lineEdit, SLOT(copy()));
    60.  
    61. QMetaObject::connectSlotsByName(palindrome);
    62. } // setupUi
    63.  
    64. void retranslateUi(QDialog *palindrome)
    65. {
    66. palindrome->setWindowTitle(QApplication::translate("palindrome", "palindrome", 0, QApplication::UnicodeUTF8));
    67. groupBox->setTitle(QApplication::translate("palindrome", "Palindrome Entry Box", 0, QApplication::UnicodeUTF8));
    68. label->setText(QApplication::translate("palindrome", "Enter number to be checked:", 0, QApplication::UnicodeUTF8));
    69. checkButton->setText(QApplication::translate("palindrome", "Check", 0, QApplication::UnicodeUTF8));
    70. pushButton_2->setText(QApplication::translate("palindrome", "Cancel", 0, QApplication::UnicodeUTF8));
    71. } // retranslateUi
    72.  
    73. };
    74.  
    75. namespace Ui {
    76. class palindrome: public Ui_palindrome {};
    77. } // namespace Ui
    78.  
    79. QT_END_NAMESPACE
    80.  
    81. #endif // UI_PALINDROME_H
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: i still get buggered: lineEdit problems

    Quote Originally Posted by Petr_Kropotkin View Post
    The following erros pop up:
    palindrome.cpp: In member function 'void palindrome:alindrome_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
    Qt Code:
    1. digit=ui->lineEdit->text().toInt();
    To copy to clipboard, switch view to plain text mode 
    See the QString docs for more.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  9. #9
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i still get buggered: lineEdit problems

    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

  10. #10
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: i still get buggered: lineEdit problems

    Don't forget to add the ui-> in front of lineEdit.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  11. #11
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i still get buggered: lineEdit problems

    That works . Thanks.
    Last edited by Petr_Kropotkin; 31st January 2010 at 15:48.

Similar Threads

  1. Help on using QTableWidget with LineEdit.
    By narendra in forum Qt Programming
    Replies: 3
    Last Post: 31st December 2009, 15:30
  2. Validate a value of lineEdit
    By edgar in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2009, 18:22
  3. LineEdit with clearbutton ...
    By momesana in forum Qt Programming
    Replies: 3
    Last Post: 13th September 2007, 18:58
  4. Slots in LineEdit
    By Misko in forum Newbie
    Replies: 3
    Last Post: 28th July 2007, 13:36
  5. cursor in LineEdit
    By Jerry in forum Qt Programming
    Replies: 1
    Last Post: 13th August 2006, 21:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.