Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 46

Thread: Display only numbers at Last

  1. #21
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Smile Re: Display only numbers at Last

    Dear Wysota,


    Thanks for the reply.......Actually i have done the validation something like this.........Just look the code phrased below

    Qt Code:
    1. QRegExp rx("([A-Za-z][A-Za-z][0-9][0-9][A-Za-z][A-Za-z][0-9]+)/([A-Za-z]+)");
    2. QValidator *validator = new QRegExpValidator(rx, this);
    3. ui->lineEditVehicleNumber->setValidator(validator);
    4. qDebug()<<"The Vehicle number is"<<rx;
    To copy to clipboard, switch view to plain text mode 



    But actually i am getting the format which i wanted to have numbers at last but im not satisfied with the coding that i have done......Can anyone remodify it......Thanks in Advance......Any solution would be appreciable.


    Regards,

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only numbers at Last

    The expression says: "Two letter upper or lower case followed by two digits followed by two letters and at least one digit then the '/' character and any number of lower or upper case letters". Is that what you wanted?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #23
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Wysota,


    Thanks for the reply......Actually i have written the code in the right way what format i need is "AP12QW1234" the last four what ever we are giving should be numbers.......Thanks in advance.........Any solution would be appreciable.......


    Regards,

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only numbers at Last

    The expression you posted will not match this string. It doesn't have a '/' character anywhere nor does it end with letters. Did you come up with this expression on your own?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #25
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Wysota,


    Thanks for the reply......yep i have done the validation by myself......Thanks in advance.........Any solution would be appreciable.......


    Regards,

  6. #26
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Display only numbers at Last

    ...and you want us to do what? I must admit I lost your question. You simply what to match AP12QW1234? Then you almost there. Alter the expression, use the web sites mentioned and all is good. If you have precise questions ask them, but
    .........Any solution would be appreciable.......
    wont help you. We will surely do not post c&p code for you.

    To be not cruel a solution can be:
    Qt Code:
    1. QRegExp rx("([A][P][1][2][Q][W][1][2][3][4])");
    2. QValidator *validator = new QRegExpValidator(rx, this);
    3. ui->lineEditVehicleNumber->setValidator(validator);
    To copy to clipboard, switch view to plain text mode 

    But real, what is your problem right now? QRegExp almost fine, only need some fine tuning.

  7. #27
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only numbers at Last

    The solution can also be:

    Qt Code:
    1. QRegExp rx("AP12QW1234");
    To copy to clipboard, switch view to plain text mode 



    @StarRocks:

    This: [A-Z] matches an uppercase letter,
    this: [0-9] matches any single decimal digit.

    To match a particular pattern more than once, repeat it an appropriate number of times, e.g. for matching two uppercase letters you'd use "[A-Z][A-Z]". To match three digits and two letters it would be "[0-9][0-9][0-9][A-Z][A-Z]".

    Now combine those to create a matching pattern for your case. You don't need any parenthesis or pluses or any other extra characters you don't understand and apparently are not willing to understand, just what I have just posted.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #28
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Lykurg and Wysote,

    Thanks for the reply......Actually don't you think this look very odd "QRegExp rx("([A][P][1][2][Q][W][1][2][3][4])");" or repeating of the same things in the validation...So i thought u would be giving me an idea about how to do not you to do.........Thanks in Advance.........


    Regards,

  9. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only numbers at Last

    First get something that works, then think if it looks odd or not. If you want to match only one string then either compare the input to a string (e.g. if(myText == "APblahblahblah") { ... }) or provide a checkbox for the user instead of the text field to let him mark if he wants to use this particular string or not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #30
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Wysota,

    Thanks for the reply......Actually the Vehicle numbers can't be same right it changes according to states so it can't be given a single string,the validation what i have written is working perfectly i just want to know repeating of the same code is a good pro-grammatical manner no i guess..So i thought we would have any other option to do this kind of validation.........Thanks in Advance......


    Regards,

  11. #31
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only numbers at Last

    So what is the final expression you came up with?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #32
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Display only numbers at Last

    The "validation" you have given us does nothing like what your originally asked for. You started with "INAP1212" and needed to check that there were 4 digits at the right and they were not "0000", then you gave us another example "IN12AP1212" which at least made sense with respect the the earlier requirement. When you gave us your first attempt at coding a validator you had an expression that matched nothing like your example and you were matching against a string containing other random text i.e. "Length: 1212AP". You then "refined" that to an expression that matched things like "Aq34Qr9/junK" or "xX22Xx123456/purpleMonkeyDishwasher" and claimed to be looking to match "AP12QW1234". That these expressions did not match your proposed input strings would have been obvious without coding anything if you used the online tools Wysota and I pointed out. It seems that ultimately your "validation" could be some form of extracting things that could licence plate numbers from within arbitrary text.. but then again maybe not.

    Can you perhaps understand why we have no real idea what you want and little faith that you do either?

    If each of the distinct licence plate patterns can be matched with a regular expression then you can simply store QRegExps in a QMap or QList and use one routine to apply the appropriate regular expression (or all of them). This might be as simple as one expression per state, or it might not, we do not know. If the patterns cannot be matched by a regular expression (it is possible) then you may need a list of validator functions/function objects each doing a complex check.

  13. #33
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Display only numbers at Last

    Dear StarRocks,

    Topics like these really sinks Indian reputation around the web.
    All though senior people here will not appreciate my post but I think OP is not going to get the RegExp thing correctly implemented.

    I will take the problem in the first post.

    This should be enough for most Strings. You do need some extra checks for length.
    Qt Code:
    1. QString str = "IN12AP1212";
    2.  
    3. bool ok = false;
    4. int num = str.right(4).toInt(&ok);
    5.  
    6. if( !ok || !num )
    7. {
    8. qDebug() << "Invalid";
    9. }
    10. else
    11. {
    12. qDebug() << "Valid!!" << num;
    13. }
    To copy to clipboard, switch view to plain text mode 

  14. #34
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Display only numbers at Last

    Quote Originally Posted by nish View Post
    All though senior people here will not appreciate my post but I think OP is not going to get the RegExp thing correctly implemented.
    I think people around here, including you, have spent more than enough time on this. Perhaps we are naive to expect that people can define the problem and want to understand why a solution they arrive at works.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  15. #35
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Display only numbers at Last

    Quote Originally Posted by ChrisW67 View Post
    Perhaps we are naive to expect that people can define the problem and want to understand why a solution they arrive at works.
    The problem is, that programming is a natural skill. You can get better by practice but what i found is that if you dont know it.. you never will. Its just like i cant become a good cricketer no matter how hard i try.

  16. #36
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Forums,

    Thanks for the reply.....Actually i have coded in Java for the numbers to display at last for sure................Please find the code for your reference......


    Qt Code:
    1. public class test {
    2. public static void main(String[] args) {
    3. String s = "abcd1000231231232131212";
    4. System.out.println(check(s));
    5. }
    6.  
    7.  
    8. public static boolean check(String s ) {
    9.  
    10. if(s.length()>=4){
    11. String s1 = s.substring(s.length()-4, s.length());
    12. System.out.println(s1);
    13. try {
    14. Integer.parseInt(s1);
    15.  
    16. if(Integer.parseInt(s1) == 0){
    17. return false;
    18. }
    19. return true;
    20. } catch (NumberFormatException e) {
    21. return false;
    22. }
    23.  
    24. }
    25. return false;
    26. }
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 


    Please provide me an idea how can it be done in button Event.......Hope you got an idea looking at this.......Any solution would be appreciable.......Thanks in Advance......


    Regards

  17. #37
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Display only numbers at Last

    Well this will be the ported C++ code. Note that exception handling in not required in this case as nothing in this code will raise an exception.

    Qt Code:
    1. #include <iostream>
    2. #include <QString>
    3.  
    4. using namespace std;
    5.  
    6. bool check(QString s)
    7. {
    8. if(s.length() >= 4)
    9. {
    10. QString s1 = s.mid(s.length()-4, s.length());
    11. cout << s1.toStdString().c_str() << endl;
    12.  
    13. bool ok = false;
    14. qulonglong Integer = s1.toULongLong(&ok);
    15.  
    16. if(ok)
    17. {
    18. return true;
    19. }
    20. else
    21. {
    22. return false;
    23. }
    24. }
    25. return false;
    26. }
    27.  
    28. int main(int argc, char *argv[])
    29. {
    30. QString s = "abcd1000231231232131212";
    31. cout << check(s) << endl;
    32. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  18. #38
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Smile Re: Display only numbers at Last

    Dear Santosh,


    Thanks for the reply......Small information that i need it from you is i want the same in the button event if it contains numbers then shld be in the if else format.....Bit confused with the code can you let me know in if-else format ..........Any Solution would be appreciable........Thanks in Advance......


    Regards,

  19. #39
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Display only numbers at Last

    Small information that i need it from you is i want the same in the button event ...
    I guess you ment button click signal

    ...if it contains numbers then shld be in the if else format...
    What is "it"?

    ...Bit confused with the code ...
    Please show some code which you are confused with.

    ...can you let me know in if-else format ...
    I already gave an example in earlier post.


    I suggest start a different thread, as the question is un-related to this threads topic
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  20. #40
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Santosh,

    Thanks for the reply.......This is my .cpp code please have a look for your reference..........

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QSqlDatabase>
    4. #include <stdio.h>
    5. #include <QTextStream>
    6. #include <QMessageBox>
    7. #include <QSqlRelationalTableModel>
    8. #include <QSqlQuery>
    9. #include <entry.h>
    10. #include <QRegExpValidator>
    11. #include <QLineEdit>
    12. #include <QValidator>
    13. #include <QComboBox>
    14. #include <qdebug.h>
    15. #include <QRegExp>
    16. #include <QValidator>
    17. #include <QRegExpValidator>
    18. #include <QPixmap>
    19. #include <QPalette>
    20. #include <QProcess>
    21. #include <QFile>
    22.  
    23. #include <Q_INT32>
    24.  
    25. MainWindow::MainWindow(QWidget *parent) :
    26. QMainWindow(parent),
    27. ui(new Ui::MainWindow)
    28. {
    29. ui->setupUi(this);
    30.  
    31. ui->lineEditpassword->setEchoMode(QLineEdit::Password);
    32. ui->lineEditUsername->setMaxLength(15);
    33. ui->lineEditpassword->setMaxLength(15);
    34.  
    35. QPixmap bg(":/images/G2G.jpg");
    36. QPalette p(palette());
    37. p.setBrush(QPalette::Background, bg);
    38. setAutoFillBackground(true);
    39. setPalette(p);
    40.  
    41. setWindowFlags(Qt::FramelessWindowHint);
    42. }
    43.  
    44. void MainWindow::changeEvent(QEvent *e)
    45. {
    46. QMainWindow::changeEvent(e);
    47.  
    48. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    49. db.setDatabaseName("/mnt/jffs2/venus.sqlite");
    50. if (!db.open()) {
    51. QMessageBox::critical(0, tr("Cannot open database"),
    52. tr("Unable to establish a database connection.\n"
    53. "This example needs SQLite support. Please read "
    54. "the Qt SQL driver documentation for information how "
    55. "to build it."), QMessageBox::Cancel);
    56. }
    57. QSqlQuery query;
    58. bool checkquery=query.exec("create table apmc (id INTEGER PRIMARY KEY AUTOINCREMENT,username varchar(20), password password, apmc varchar(20))");
    59. qDebug()<<checkquery;
    60. switch (e->type()) {
    61. case QEvent::LanguageChange:
    62. ui->retranslateUi(this);
    63. break;
    64. default:
    65. break;
    66. db.close();
    67. }
    68. }
    69.  
    70.  
    71. void MainWindow::on_pushButtonLogin_clicked()
    72. {
    73. QSqlQuery query;
    74. QMessageBox* msgR=new QMessageBox(this);
    75.  
    76. QString UserName = ui->lineEditUsername->displayText();
    77. QString Password = ui->lineEditpassword->text();
    78. QString apmc=ui->comboBoxApmc->currentText();
    79. qDebug()<<UserName.isEmpty();
    80. qDebug()<<Password.isEmpty();
    81.  
    82.  
    83.  
    84.  
    85. if(UserName.isEmpty())
    86. {
    87. QMessageBox::critical(0, tr("UserName"),
    88. tr("Please Enter the UserName"), QMessageBox::Cancel);
    89. }
    90.  
    91. else if(UserName.length()>=4)
    92. {
    93.  
    94. QString s = ui->lineEditUsername->displayText();
    95.  
    96. QString s1 = s.mid(s.length()-4, s.length());
    97. qDebug()<<s1.toStdString().c_str() << "What is the value of s1";
    98.  
    99. qDebug()<<"The Value of s1 is : "<<s1;
    100.  
    101. bool ok = false;
    102. qulonglong Integer = s1.toULongLong(&ok);
    103.  
    104. qDebug()<<"Print for me"<<Integer;
    105. if(ok)
    106. {
    107. qDebug()<<"True";
    108. }
    109. else
    110. {
    111. qDebug()<<"False";
    112.  
    113. QMessageBox::critical(0, tr("UserName"),
    114. tr("Please Enter the UserName in right format"), QMessageBox::Cancel);
    115.  
    116.  
    117. ui->lineEditUsername->clear();
    118. ui->lineEditpassword->clear();
    119.  
    120. }
    121.  
    122. }
    123. else if(Password.isEmpty())
    124. {
    125. QMessageBox::critical(0, tr("Password"),
    126. tr("Please Enter the Password"), QMessageBox::Cancel);
    127. }
    128.  
    129. else if(apmc=="None")
    130. {
    131. QMessageBox::critical(0, tr("Apmc"),
    132. tr("Please Enter the Apmc"), QMessageBox::Cancel);
    133. }
    134. else
    135. {
    136.  
    137. qDebug()<<ui->lineEditUsername->displayText();
    138.  
    139. bool check=query.exec("insert into apmc (username,password,apmc) values('" + ui->lineEditUsername->displayText() + "','" + ui->lineEditpassword->text() + "' ,'" + ui->comboBoxApmc->currentText()+"')");
    140. qDebug()<<"insertino chekc-----------------"<<check;
    141. msgR->setText("Inserted Successfully");
    142.  
    143. QPixmap bg("/home/venugopal/MyQTProjects/G2G/images/G2G.jpg");
    144. QPalette p(palette());
    145.  
    146. p.setBrush(QPalette::Background, bg);
    147. setAutoFillBackground(true);
    148. msgR->setPalette(p);
    149. msgR->exec();
    150. this->close();
    151. Entry* e=new Entry();
    152. e->show();
    153. }
    154.  
    155. }
    156.  
    157. void MainWindow::on_Delete_clicked()
    158. {
    159. system("rm -Rf /home/venugopal/sample/venu.xml");
    160. }
    To copy to clipboard, switch view to plain text mode 


    When i try to perform this action giving only alphabets i am getting the error message that to enter the Username in right format and when i enter the Username with alphabets followed by number its not getting submitted in the button event rather its getting terminated.......Hope you got me........Any Ideas would be appreciable.........Thanks in Advance....


    Regards,

Similar Threads

  1. Replies: 2
    Last Post: 26th January 2012, 16:31
  2. How to display the numbers in a QList<QString> ?
    By harish in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2012, 05:26
  3. Replies: 1
    Last Post: 18th June 2011, 19:28
  4. Replies: 3
    Last Post: 17th April 2010, 22:35
  5. How to use QLCDnumber to display negative numbers?
    By grissiom in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2010, 07:23

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.