You are not logged in.

1

Wednesday, October 31st 2012, 9:44am

QProcess and Unicode Problem

Hi all,
my Qt application calls a QProcess with a unicode command and I get question marks returned as the output. I read somewhere that I need to change my application's entry point from "main" to "wWinMain" in order to have a unicode enabled program. I have no idea how to do that, can someone provide some pointer please? Thanks!
Best, Pat

Junior

Professional

  • "Junior" is male

Posts: 1,623

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

2

Wednesday, October 31st 2012, 12:35pm

Pat,

I have not heard that before, but I do know using the QString class you can translate back and forth unicode, and QProcess takes QString as an arg.
Example of that if it helps:

main.cpp

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <QtCore/QDebug>
#include <QtCore/QChar>

int main()
{
	QString str = "Hello World!";
	QString ustr;
	const QChar *char_ptr;

	qDebug() << "  Original QString: " << str;
	char_ptr = str.unicode();
                   
        // unicode values of each
         foreach( QChar ch, str ) {
            qDebug() << ch.unicode();
        }

	qDebug() << "QString to unicode (start addr): " << char_ptr;

	ustr = ustr.setUnicode( char_ptr, str.size() );
	qDebug() << "unicode to QString: " << ustr;

	return EXIT_SUCCESS;
}

This post has been edited 3 times, last edit by "Junior" (Oct 31st 2012, 1:01pm)


3

Wednesday, October 31st 2012, 3:59pm

Hi Junior,

Thank you for that. My original QString is a unicode string already and the debugger displays it correctly. When I pass this string to the QProcess::start function, the process is executed but all non-ASCII characters in the command string are interpreted as "?" by the commandline interpreter. Somehow my commandline is not unicode enabled ...

Best, Pat