You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

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