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. How to read and write data in Visual FoxPro files in Windows-1251.
QtWS25 Last Chance

How to read and write data in Visual FoxPro files in Windows-1251.

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 975 Views
  • 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.
  • A Offline
    A Offline
    Andrey Yachmenev
    wrote on last edited by
    #1

    Hi all,
    I use Qt5.3 for Windows 7 64bit. I try to read and write data in Visual FoxPro files in Windows-1251 but Cyrillic characters display as gibberish (????). That is my code:
    @
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("Windows-1251"));

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setDatabaseName("DRIVER={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:/database;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO;");
    db.open();

    QSqlQuery query;
    query.exec("SELECT * FROM sale");

    while (query.next())
    {
    QString code = query.value(0).toByteArray();
    QString name = query.value(1).toByteArray();
    QString price = query.value(2).toByteArray();
    qDebug() << code << name << price;
    }
    @

    or

    @
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("Windows-1251"));

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setDatabaseName("DRIVER={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:/database;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO;");
    db.open();

    QSqlQuery query;
    query.exec("SELECT * FROM sale");

    QTextCodec * codec = QTextCodec::codecForName("Windows-1251");
    while (query.next())
    {
    QString code = codec->toUnicode(query.value(0).toByteArray());
    QString name = codec->toUnicode(query.value(1).toByteArray());
    QString price = codec->toUnicode(query.value(2).toByteArray());
    qDebug() << code << name << price;
    }
    @
    Why does it happen? Can you give me some advice on how to decide my question?

    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