I created a driver for a widget and it runs perfectly, but I traslate it to Qt it does not work.
Here is the driver program:
Qt Code:
  1. void rule(int digit,int x, int place[])
  2. {
  3.  
  4. int n,flag=0;
  5. if(x % 2>0)
  6. n=floor(x/2);
  7. else
  8. n=x/2;
  9.  
  10. for(int i=0;i<n;++i)
  11. if (place[i]==place[n-i])
  12. flag++;
  13. if (flag==n)
  14. std::cout <<" "<<digit<<" is a palindrome";
  15. else
  16. std::cout<<" " <<digit<<" is not a palindrome";
  17.  
  18.  
  19.  
  20. }
  21.  
  22.  
  23. int pow(int a ,int b)
  24. {
  25. int i=1,power=1;
  26. while(i<b)
  27. {
  28. power *=a;
  29. ++i;
  30.  
  31. }
  32. return power;
  33.  
  34.  
  35. }
  36.  
  37.  
  38. int main()
  39. {
  40.  
  41. int rem[10],digit,n,x=1,place[10];
  42. std::cout << "\nEnter another number :";
  43. std::cin>>digit;
  44. n= sizeof digit;
  45. std::cout<<"\nn= "<< n;
  46. rem[0]= digit % pow(10,n);
  47. place[0]= (digit-rem[0])/pow(10,n);
  48. while( x<n)
  49. {
  50. rem[x]=rem[x-1] % pow(10,n-x);
  51. place[x]=(rem[x-1]-rem[x])/pow(10,n-x);
  52.  
  53. x++;
  54. }
  55. rule(digit,x,place);
  56.  
  57. system("Pause");
  58.  
  59. }
To copy to clipboard, switch view to plain text mode 

When run it Qt any number typed in states it is not a palindrome, but in the driver it worls
Here is the Qt version

Qt Code:
  1. #include "ui_palindrome.h"
  2. #include "palindrome.h"
  3. #include <QString>
  4. #include <QtGui>
  5. #include <QLineEdit>
  6. #include <QPushButton>
  7. #include <QSize>
  8.  
  9.  
  10. void rule(int x, int place[],QLineEdit *lineEdit)
  11. {
  12. QString msg=lineEdit->text()+" is a palindrome";
  13. QString msg2=lineEdit->text()+" is not a palindrome";
  14. QMessageBox msgbox;
  15. int n,flag=0;
  16.  
  17. if(x % 2>0)
  18. n=floor(x/2);
  19. else
  20. n=x/2;
  21.  
  22.  
  23. for(int i=0;i<n;++i)
  24. if (place[i]==place[n-i])
  25. flag++;
  26. if (flag==n)
  27.  
  28. msgbox.setText(msg);
  29. else
  30. msgbox.setText(msg2);
  31.  
  32. msgbox.exec();
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40. int pow(int a ,int b)
  41. {
  42. int i=1,power=1;
  43. while(i<b)
  44. {
  45. power *=a;
  46. ++i;
  47. }
  48. return power;
  49.  
  50. }
  51.  
  52.  
  53.  
  54. palindrome::palindrome(QWidget *parent) :
  55. QDialog(parent)
  56.  
  57. {
  58. setupUi(this);
  59. connect(checkButton, SIGNAL(clicked(bool)), this, SLOT(palindrome_checker()));
  60. }
  61.  
  62.  
  63. palindrome::~palindrome()
  64. {
  65. delete this;
  66. }
  67.  
  68.  
  69.  
  70. void palindrome::palindrome_checker()
  71. {
  72. int remainder[10],place[10],digit,x=1,m=0;
  73.  
  74. digit=lineEdit->text().toInt();
  75. m=lineEdit->text().size();
  76. remainder[0]= digit % pow(10,m);
  77. place[0]= (digit-remainder[0])/pow(10,m);
  78. m=lineEdit->text().size();
  79. while(x<m)
  80. {
  81. remainder[x]=remainder[x-1] % pow(10,m-x);
  82. place[x]=(remainder[x-1]-remainder[x])/pow(10,m-x);
  83. ++x;
  84. }
  85.  
  86. rule(x, place,lineEdit );
  87.  
  88. }
To copy to clipboard, switch view to plain text mode 

I posted problems with this widge & I thought I was, as far interface goes it reacts when a number is put in.
I think the problem might be
Qt Code:
  1. m=lineEdit->text().size();
To copy to clipboard, switch view to plain text mode 
but according to the documentation size() returns the size() of lineEdit->text() as an int.
Help !