Results 1 to 5 of 5

Thread: Convertion between QLineEdit formated to Double

  1. #1
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Convertion between QLineEdit formated to Double

    Hi,

    How I can convert a QLineEdit with editmask 999.999.999,99 to a double?

    If I use lineedit->text().toDouble() only 0(zeros) are returned.

    Thanks for help

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

    Default Re: Convertion between QLineEdit formated to Double

    try this
    Qt Code:
    1. QString text = ineedit->text();
    2. text.remove( QChar( '.' ) );
    3. text.toDouble();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: Convertion between QLineEdit formated to Double

    No, see the results:

    Value: 111.222.333,44

    If I use your code the result is: 1.11222e+08

    I really don't know what I do!
    Thanks

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

    Default Re: Convertion between QLineEdit formated to Double

    it's kind of notation, use
    Qt Code:
    1. qDebug( "%f", your_variable );
    To copy to clipboard, switch view to plain text mode 
    and you will see what you want

  5. #5
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convertion between QLineEdit formated to Double

    Thanks for your help.
    You help-me to understand the process.

    Now I'm using this:

    QLocale locale;

    locale.setDefault(QLocale::German); // Decimal point is Comma: 000.000,00
    locale.setNumberOptions(QLocale::OmitGroupSeparato r);


    bool ok;
    double d;
    d = locale.toDouble( LE_TEST->text(), &ok );
    if(ok) {
    qDebug( "%f", d );
    }

    The LE_TEST is using inputMask: 999.999.999,99

    Thanks

Similar Threads

  1. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 15:13

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.