Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Beginner question: forcing comma into point
Forum Updated to NodeBB v4.3 + New Features

Beginner question: forcing comma into point

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 925 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rutschuru
    wrote on last edited by
    #1

    Hello,

    how can I force LineEdit to replace comma into point?
    I have to want make a little calculate-similar tool.

    @
    double value =
    ui->lineEdit->text().toDouble(); // for Example: value is: 500 comma 32

    calculateProcess() .....

    backCasting()....
    @

    So I want to force lineEdit to casting the comma to point automaticly. How can I do that?

    I cant use this:

    @
    QLocale current(QLocale("de_DE"));
    current.setNumberOptions(QLocale::c().numberOptions());
    QLocale::setDefault(current);
    @

    because I got diverse error-message :(

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,
      You can subclass a "QValidator":http://qt-project.org/doc/qt-5.1/qtgui/qvalidator.html and implement the validate() method to do whatever string transformations you need. Then just set it on the QLineEdit with "setValidator()":http://qt-project.org/doc/qt-5.1/qtwidgets/qlineedit.html#setValidator

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        [quote author="Rutschuru" date="1386515682"]
        because I got diverse error-message :([/quote]
        What kind of error messages?

        See "this":http://qt-project.org/doc/qt-4.8/qlocale.html#toDouble.
        Also see QLocale::decimalPoint() and QLocale::groupSeparator() and make sure you have set the QLocale on the line edit.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved