Results 1 to 14 of 14

Thread: QLineedit Multiple Validation

  1. #1
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QLineedit Multiple Validation

    I have a LineEdit. I need to validate the input of this lineEdit for Latitude and longitude!
    i.e., i have only one lineedit in which i have to validate the first to digits for 0-90 the next two for 0-60 and the next two for 0-60 and the last for [NWES].

    will the method of reqexp work here!
    if so how will i add input mask.

    --
    Thanks

  2. #2
    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: QLineedit Multiple Validation

    You have many different choices here. I'd go for providing a custom (not regexp) validator. Another choice is to implement a spinbox that will let you set the coordinates just as QDateTimeEdit does for date and time.

  3. #3
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineedit Multiple Validation

    i dont want to use a spin box..
    i would like to use a lineedit only, in that case, how will i write a custom validator without regexp?

    some examples or tips please..

  4. #4
    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: QLineedit Multiple Validation

    Implement a subclass of QValidator?

  5. #5
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineedit Multiple Validation

    is thereany method in QString that is equivalent to
    char charAt(int );

    that is i need a method that will give the character at the index given.

  6. #6
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLineedit Multiple Validation


  7. #7
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineedit Multiple Validation

    is it possible to find out who has called a particular slot when there are many senders connected to the same slot for the same signal.?

    i have a slot that should be called when a lineedit looses its focus and i will set the lineedit's text to some value. this is done by a custom slot.

    now i will have many lineedits connected to same slot so that only the particular lineedit which has lost the focus will have the text set. how will i do this.?

    --
    Thanks

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineedit Multiple Validation

    Yes...
    By QObject::sender () you can find the sender, cast it into proper object and you are done

  9. #9
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineedit Multiple Validation

    thanks working fine!
    Last edited by csvivek; 22nd April 2008 at 11:15.

  10. #10
    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: QLineedit Multiple Validation

    Quote Originally Posted by csvivek View Post
    is it possible to find out who has called a particular slot when there are many senders connected to the same slot for the same signal.?

    i have a slot that should be called when a lineedit looses its focus and i will set the lineedit's text to some value. this is done by a custom slot.

    now i will have many lineedits connected to same slot so that only the particular lineedit which has lost the focus will have the text set. how will i do this.?
    But really... why not use a subclass of QValidator? Unless you are using sender() for some other purpose than validating the input.

  11. #11
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineedit Multiple Validation

    i think that will be a bit complex!

  12. #12
    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: QLineedit Multiple Validation

    Complex? Like... 10 lines of code?

  13. #13
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: QLineedit Multiple Validation

    Quote Originally Posted by wysota View Post
    Complex? Like... 10 lines of code?
    Hi!

    Could someone write a simple code of QLineEdit Validation? (maybe for 2 QLineEdits?).

    Thanks in advance!!


    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  14. #14
    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: QLineedit Multiple Validation

    You can validate lat/long with a regexp:

    Qt Code:
    1. QRegExp rx("([0-8][0-9])|([0-9]0?)\s*[NS]\s+(1[0-7][0-9])|(180)|([0-9][0-9]?)\s*[EW]");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25
  2. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05: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.