Page 1 of 3 123 LastLast
Results 1 to 20 of 46

Thread: Display only numbers at Last

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

    Smile Display only numbers at Last

    Dear Forums,


    I have small doubt in QT..... Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000.............I need a validation for it.........Can anyone make it out for me...........Any solution would be appreciable....


    Regards,

    Venugopal.T

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display only numbers at Last

    Quote Originally Posted by StarRocks View Post
    Dear Forums,


    I have small doubt in QT..... Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000.............I need a validation for it.........Can anyone make it out for me...........Any solution would be appreciable....


    Regards,

    Venugopal.T
    I am sorry if it sounds condescending, but you need to understand how this forum works. You have been opening several new topics recently, in which you always ask someone to solve a problem for you, without showing that you actually tried anything on your own. Guess what: the people who help each other here do so for free, in their free time. They will only help you solve your problem, not do it for you. If you are looking for someone to do your work for you, just hire some seasoned Qt developer.

    I suggest you try harder, explain what you have tried; I am confident that someone will then help you.

  3. The following user says thank you to yeye_olive for this useful post:

    d_stranz (7th August 2012)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,197
    Thanks
    237
    Thanked 668 Times in 658 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Display only numbers at Last

    I have small doubt in QT..... Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000.............I need a validation for it.........Can anyone make it out for me...........Any solution would be appreciable....
    You don't explain anything about how or where you want to do this validation. So, if you are trying to validate input into a QLineEdit widget, then I suggest you read about QValidator, QRegExp, and QRegExpValidator. Those classes will allow you to write a validator for the problem you have described.

    And like yeye_olive says, don't simply reply with "OK, give me example code for that". Try it on your own, and if you still can't solve it, post your code and ask what you are doing wrong.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #4
    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

    Hi Guys,

    Thanks for your feedback.........Listen i have posted few queries which i solved by my own noone gave any solutions.......First have a look at my queries im posting queries which i tried a lot and only then im posting to my knowledge that queries are not that easy to solve i guess.........Im not jus posting without trying sorry if i hurt u guys.........

    Regards,

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,197
    Thanks
    237
    Thanked 668 Times in 658 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Display only numbers at Last

    I have small doubt in QT..... Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000.............I need a validation for it.........Can anyone make it out for me...........Any solution would be appreciable....
    @StarRocks: Look at what you said here. You did not say anything at all about having tried something. You didn't post any code and ask "Why doesn't this work"? You just said "Here's my problem. Tell me the answer".

    So when you post something like that, what are we supposed to think? Next time, tell us what you've tried and what didn't work so we can at least tell that you aren't just begging for free answers. You will be much more likely to get some help instead of abuse in that case.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #6
    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 d_stranz,

    Its not like im begging for answers and all..............Please understand that first and i have written a code in Javascript and its working for me but i cant implement the same for C++ right....
    As im new to Qt so i want to know how to use that coz its only validation prob ...........For ur reference the below is the code...






    function ValidateVehicleNumber(strVarInstance) {
    var strResult = "";
    var cnt = 0;
    var count1 = 0;
    if (strVarInstance[1] == '') {
    cnt++;
    strResult += "";
    }
    else {
    var VehicleNo = strVarInstance[1];

    if (VehicleNo.length < 4) {
    cnt++;

    strResult += "Vehicle Number contains Atleast four digits \n ";
    }
    else {
    var index = VehicleNo.length - 4
    var count = 0;
    for (i = index; i < VehicleNo.length; i++)
    {
    var c = VehicleNo.charAt(i);

    if (isNaN(c) || c == " " )
    {
    count++;
    }
    if (c == 0) {
    count1++;
    }
    }
    if (count != 0)
    {
    cnt++;

    strResult += "Last four character of Vehicle Number digits only \n ";
    }
    if (count1 == 4) {
    cnt++;

    strResult += "Vehicle Number should not be zeros \n ";

    }
    }
    }
    return strResult;
    }


    Regards

  8. #7
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display only numbers at Last

    In order to port this code as-is to Qt you need to do the following (in this order):
    1. learn C++;
    2. learn some Qt basics;
    3. have a look at the documentation for the QString and QChar classes, that you will use to represent strings and characters respectively. All the operations you need are there.

    However you can probably replace all this code with a simple regular expression. Once you have done steps 1 and 2 above, you can have a look at QRegExp, which d_stranz mentioned above. The documentation of the class explains the syntax of regular expressions and gives some examples that among other things show how to match digits in a string.

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

    Smile Display only numbers at Last



    Dear Forums,


    Thanks for the reply .......Will go through the things that you asked me to if any doubts will contact you..........


    Regards,

  10. #9
    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,

    As i have posted previously too i have google searched validations for everything i have got most of them but except the one im searching for i.e having numbers at the last i have tried but achieved only in having something like this as "ap12" but i have to get only numbers after that....Hope you got me......example is IN12AP1212.........Thanks in Advance.......Any solution would be appreciable.....


    Regards,

  11. #10
    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

    Have you tried to check the strings with a regular expression? See QRegularExpression.

  12. #11
    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,

    Thanks for the reply....I have gone through the QRegularExpression but dint find any solution through that so posted in the forums again......Any solution would be appreciable.......

    Regards,

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 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

    Open the QRegularExpression documentation again and instead of looking for a solution there, read the documentation with understanding.
    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.


  14. #13
    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........I have read the documentation i have used most of the syntax in my application but not finding the required....Its not that i have only looked for the solution have even read the docs........Any solution would be appreciable......Thanks in Advance........


    Regards,

  15. #14
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,555
    Thanks
    13
    Thanked 1,581 Times in 1,510 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Display only numbers at Last

    Show us what you have tried to do with those classes rather than just telling us that you have "used most of the syntax in my application" or that you "have even read the docs". We cannot fix or guide based on what we cannot see.

    This is how you show us. Copy the following two lines into a reply:
    [code]
    [/code]

    Then, between the two tags, paste your best attempt at coding the function to validate the input and press Submit Reply.

    The solution can be had using only the classes pointed out in this thread. I estimate an equivalent of your script routine consists of less than twenty lines. That depends a little on exactly what "strVarInstance" represents because the script code is, well, odd.

  16. #15
    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 Chris,


    Thanks for the reply......Please find the below code about how i used one of the syntax for my application.........

    Qt Code:
    1. QRegExp rxlen("(\\d+)(?:\\s*)([0-9]|[A-Z])");
    2. int pos = rxlen.indexIn("Length: 1212AP");
    3.  
    4. if (pos > -1) {
    5. QString value = rxlen.cap(1); // "189"
    6. QString unit = rxlen.cap(2); // "cm"
    7.  
    8. QString uts = rxlen.cap(3);
    9.  
    10. qDebug()<<value<<"The Value is";
    11. qDebug()<<unit<<"The Unit is";
    12. qDebug()<<uts<<"The Uts is";
    To copy to clipboard, switch view to plain text mode 


    Thanks in Advance.....Any solution would be appreciable........



    Regards,

  17. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 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

    Your expression reads: one or more digits followed by a 0 or more white spaces followed by a digit or capital letter. There is no cap(3) here. Did you really think this expression would match a string such as "INAP1212"?

    Quote Originally Posted by StarRocks
    Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000
    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.


  18. #17
    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 in my code i have commented that line but forgot to do the same in the coding that i have posted........Hope you understood the situation that i have posted.........Any solution would be appreciable.......Thanks in Advance...Actually i am not exactly knowing how to have syntax in that format...


    Regards,

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 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 expression did you code if it wasn't the one you 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.


  20. #19
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,555
    Thanks
    13
    Thanked 1,581 Times in 1,510 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Display only numbers at Last

    Concentrate on getting a regular expression that matches 4 or more digits. Once you have that extend it by forcing the match to only occur at the end of the string and you will be most of the way there. You may find an online regular expression tester a useful tool to help learn in conjunction with the Qt docs.

  21. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 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

    This one is also ok: http://www.regexper.com/
    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.


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.