Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-15247

QApplication changes behaviour of system functions like scanf...

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 4.6.2, 4.6.3, 4.7.1
    • None
    • None
    • Ubuntu 9.1, 10.04, 10.10

    Description

      After creating a new QApplication the behaviour for handling the decimal point in standard library functions like sscanf, fscanf, ... is changed.
      Before the QApplication is created a dot will be used as decimal point and after creating the QApplication a coma will be used.
      This effects only the linux version not the windows version of Qt.
      The language profile for the system must be set to a language that uses a coma as decimal point e.g. a german layout.

      #include <QApplication>
      #include <stdio.h>
      
      int main(int argc, char *argv[])
      {
        char xxx[]="3.212 -1.23";
        float x=0.0f;
        float y=0.0f;
        sscanf(xxx, "%f %f", &x,&y);
        printf("Read the following values %f %f\n", x,y);
        x=0.0f;
        y=0.0f;
      
        QApplication app(argc, argv);
        sscanf(xxx, "%f %f", &x,&y);
        printf("Read the following values %f %f\n", x,y);
        return 1;
      }
      

      --> The code produces
      Read the following values 3.212000 -1.230000
      Read the following values 3,000000 0,000000

      on my system.

      My current workaround for this is to set the LC_NUMERIC to posix after the QApplication has been created
      setlocale(LC_NUMERIC, "POSIX");

      Maybe it is a bug in Ubuntu as well that the LC_NUMERIC variable is not set by default, but anyway, the creation of a QApplication object shouldn't change the program behaviour.

      Regards,
      Benny

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            dzyubenk Denis Dzyubenko (Inactive)
            bbuerger Benny Bürger
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes