Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4109162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:45:33+00:00 2026-05-20T21:45:33+00:00

I have some issues with character encoding of a binary value using Qt4 and

  • 0

I have some issues with character encoding of a binary value using Qt4 and MySQL5.

Let’s say we want to bind a value containing the four bytes \xDE \xAD \xBE \xEF. I check the bound value using the MySQL function HEX() using this code:

#include <QtGui/QApplication>
#include <QDebug>
#include <QSqlQuery>
#include <QVariant>
#include <QSqlRecord>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    if(!db.open("test", "test"))
        exit(1);

    QSqlQuery q("SELECT HEX(?)");
    q.addBindValue(QVariant(QByteArray::fromHex("DEADBEEF")));
    if(!q.exec())
        exit(1);
    if(!q.next())
        exit(1);

    qDebug() << q.record().value(0).toString();

    return a.exec();
}

The output of this code is "DEADEFBFBDEFBFBD" which is obviously the HEX code of \xDE \xAD \xBE \xEF interpreted as a latin1-encoded string and then encoded as a UTF8 string.

If I do not bind the value using addBindValue() but placing it directly into the query using UNHEX('DEADBEEF') results in the expected behaviour (which isn’t surprising…).

Where does the UTF8 encoding step take place?

(Finally, I want to store a binary value “1:1” into a BLOB field.)

OS: Ubuntu 10.10 (32 bit)
Qt Version: 4.7.0 (Ubuntu package)
MySQL Version: 5.1.49-1ubuntu8.1

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:45:33+00:00Added an answer on May 20, 2026 at 9:45 pm

    After weeks of trial and error, the only solution I found is to transfer the binary data in hexadecimal code and UNHEX() it in the query.

    This is a solution, so I allow myself to accept my own answer, but it isn’t a nice solution and I have no explanation to the behavior of the code above.

    So if you have any advice, I am looking forward for any further answer. (I will then accept your answer.) Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some issues with my email -body when i send mails I'm using
I have an issue while storing some special character values into db. For e.g.
I have some issues in setting the classpath for the a project for which
I have some issues with a PHP file that is not working properly. The
I have some issues with my EJB 3 timer where it is launched more
I'm have some issues adding a class to 2 navigation links on a theme.
I seems to have some issues in order to compile gproc from uwiger. I
Im starting with CoCos2d development and I think I have some issues with nodespace,
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
I am integrating PayPal in my website But I have some issues in it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.