pass unicode arguments to QApplication
up vote
1
down vote
favorite
I have windows console application which accepts unicode characters as argument
wmain( int argc , wchar_t ** argv)
Now I want to pass the argv argument to my QApplication . However the QApplication accepts on char ** .
How do I manage to achieve this ?
c++ qt unicode
add a comment |
up vote
1
down vote
favorite
I have windows console application which accepts unicode characters as argument
wmain( int argc , wchar_t ** argv)
Now I want to pass the argv argument to my QApplication . However the QApplication accepts on char ** .
How do I manage to achieve this ?
c++ qt unicode
Either, you usemain()
instead or you "translate"wchar_t
s tochar
s. I cannot imagine thatQApplication
expects command line arguments where non-ASCII values are relevant but actually I'm not sure. File paths would be the exception.
– Scheff
Nov 22 at 13:53
IIRCQApplication::arguments
on Windows is already Unicode-aware. Write portable code, usingint main(int argc, char**argv)
and Qt will magically make it work.
– MSalters
Nov 22 at 14:29
1
according to this answer the constructor argumenrt are not used to constructQApplication::arguments()
. So you could as well not bother.
– max630
Nov 25 at 8:38
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have windows console application which accepts unicode characters as argument
wmain( int argc , wchar_t ** argv)
Now I want to pass the argv argument to my QApplication . However the QApplication accepts on char ** .
How do I manage to achieve this ?
c++ qt unicode
I have windows console application which accepts unicode characters as argument
wmain( int argc , wchar_t ** argv)
Now I want to pass the argv argument to my QApplication . However the QApplication accepts on char ** .
How do I manage to achieve this ?
c++ qt unicode
c++ qt unicode
asked Nov 22 at 13:49
sameer karjatkar
88531232
88531232
Either, you usemain()
instead or you "translate"wchar_t
s tochar
s. I cannot imagine thatQApplication
expects command line arguments where non-ASCII values are relevant but actually I'm not sure. File paths would be the exception.
– Scheff
Nov 22 at 13:53
IIRCQApplication::arguments
on Windows is already Unicode-aware. Write portable code, usingint main(int argc, char**argv)
and Qt will magically make it work.
– MSalters
Nov 22 at 14:29
1
according to this answer the constructor argumenrt are not used to constructQApplication::arguments()
. So you could as well not bother.
– max630
Nov 25 at 8:38
add a comment |
Either, you usemain()
instead or you "translate"wchar_t
s tochar
s. I cannot imagine thatQApplication
expects command line arguments where non-ASCII values are relevant but actually I'm not sure. File paths would be the exception.
– Scheff
Nov 22 at 13:53
IIRCQApplication::arguments
on Windows is already Unicode-aware. Write portable code, usingint main(int argc, char**argv)
and Qt will magically make it work.
– MSalters
Nov 22 at 14:29
1
according to this answer the constructor argumenrt are not used to constructQApplication::arguments()
. So you could as well not bother.
– max630
Nov 25 at 8:38
Either, you use
main()
instead or you "translate" wchar_t
s to char
s. I cannot imagine that QApplication
expects command line arguments where non-ASCII values are relevant but actually I'm not sure. File paths would be the exception.– Scheff
Nov 22 at 13:53
Either, you use
main()
instead or you "translate" wchar_t
s to char
s. I cannot imagine that QApplication
expects command line arguments where non-ASCII values are relevant but actually I'm not sure. File paths would be the exception.– Scheff
Nov 22 at 13:53
IIRC
QApplication::arguments
on Windows is already Unicode-aware. Write portable code, using int main(int argc, char**argv)
and Qt will magically make it work.– MSalters
Nov 22 at 14:29
IIRC
QApplication::arguments
on Windows is already Unicode-aware. Write portable code, using int main(int argc, char**argv)
and Qt will magically make it work.– MSalters
Nov 22 at 14:29
1
1
according to this answer the constructor argumenrt are not used to construct
QApplication::arguments()
. So you could as well not bother.– max630
Nov 25 at 8:38
according to this answer the constructor argumenrt are not used to construct
QApplication::arguments()
. So you could as well not bother.– max630
Nov 25 at 8:38
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
Until QTBUG-3200 is fixed, the only way to not be bounded by the "Current locale for non-Unicode" charset seem to convert the arguments to UTF-8, then
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
QApplication(argc, argv_converted);
I cannot verify currently that it would work, though.
add a comment |
up vote
1
down vote
You don’t need to pass these arguments to QApplication
constructor. You can pass a dummy array, since it’s not used on Windows. The C-style program argument passing via main
arguments is not the Windows-native way of accessing arguments, and QApplication
doesn’t use it. The wchar
-based main
is a kludge that attempts to distract from the fact that argv
is not a native interface.
This works:
int argcc = 1;
char arg0[1] = "";
char *argvc[2] = {&arg0, nullptr};
QApplication app(argcc, argvc);
add a comment |
up vote
-1
down vote
Qt do not use wchar_t* for Unicode strings as usual. Only QString or char*. If you want to contvert QString -> char* (or char* -> QString) use QTextCodec.
For example, older versions of Windows has encoding cp866
for console and if you want send unicode QString into command line:
QString string = "Unicode text";
QTextCodec *codec = QTextCodec::codecForName("cp866");
QByteArray encodedString = codec->fromUnicode(string);
//encodedString.data() - char* representation of unicode QString
For reading input parameters in main()
convert like this:
QTextCodec *codec = QTextCodec::codecForName("cp866");
QString strArg = codec->toUnicode(argv);
I think you should mentionQChar*
, which is the direct Qt alternative towchar_t*
.
– MSalters
Nov 22 at 14:26
1
Also note that code page 866 is Cyrillic; it's the default on a very small number of PC's worldwide.
– MSalters
Nov 22 at 15:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432448%2fpass-unicode-arguments-to-qapplication%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Until QTBUG-3200 is fixed, the only way to not be bounded by the "Current locale for non-Unicode" charset seem to convert the arguments to UTF-8, then
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
QApplication(argc, argv_converted);
I cannot verify currently that it would work, though.
add a comment |
up vote
1
down vote
Until QTBUG-3200 is fixed, the only way to not be bounded by the "Current locale for non-Unicode" charset seem to convert the arguments to UTF-8, then
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
QApplication(argc, argv_converted);
I cannot verify currently that it would work, though.
add a comment |
up vote
1
down vote
up vote
1
down vote
Until QTBUG-3200 is fixed, the only way to not be bounded by the "Current locale for non-Unicode" charset seem to convert the arguments to UTF-8, then
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
QApplication(argc, argv_converted);
I cannot verify currently that it would work, though.
Until QTBUG-3200 is fixed, the only way to not be bounded by the "Current locale for non-Unicode" charset seem to convert the arguments to UTF-8, then
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
QApplication(argc, argv_converted);
I cannot verify currently that it would work, though.
answered Nov 25 at 8:31
max630
5,17111340
5,17111340
add a comment |
add a comment |
up vote
1
down vote
You don’t need to pass these arguments to QApplication
constructor. You can pass a dummy array, since it’s not used on Windows. The C-style program argument passing via main
arguments is not the Windows-native way of accessing arguments, and QApplication
doesn’t use it. The wchar
-based main
is a kludge that attempts to distract from the fact that argv
is not a native interface.
This works:
int argcc = 1;
char arg0[1] = "";
char *argvc[2] = {&arg0, nullptr};
QApplication app(argcc, argvc);
add a comment |
up vote
1
down vote
You don’t need to pass these arguments to QApplication
constructor. You can pass a dummy array, since it’s not used on Windows. The C-style program argument passing via main
arguments is not the Windows-native way of accessing arguments, and QApplication
doesn’t use it. The wchar
-based main
is a kludge that attempts to distract from the fact that argv
is not a native interface.
This works:
int argcc = 1;
char arg0[1] = "";
char *argvc[2] = {&arg0, nullptr};
QApplication app(argcc, argvc);
add a comment |
up vote
1
down vote
up vote
1
down vote
You don’t need to pass these arguments to QApplication
constructor. You can pass a dummy array, since it’s not used on Windows. The C-style program argument passing via main
arguments is not the Windows-native way of accessing arguments, and QApplication
doesn’t use it. The wchar
-based main
is a kludge that attempts to distract from the fact that argv
is not a native interface.
This works:
int argcc = 1;
char arg0[1] = "";
char *argvc[2] = {&arg0, nullptr};
QApplication app(argcc, argvc);
You don’t need to pass these arguments to QApplication
constructor. You can pass a dummy array, since it’s not used on Windows. The C-style program argument passing via main
arguments is not the Windows-native way of accessing arguments, and QApplication
doesn’t use it. The wchar
-based main
is a kludge that attempts to distract from the fact that argv
is not a native interface.
This works:
int argcc = 1;
char arg0[1] = "";
char *argvc[2] = {&arg0, nullptr};
QApplication app(argcc, argvc);
answered Nov 25 at 8:47
Kuba Ober
69k982182
69k982182
add a comment |
add a comment |
up vote
-1
down vote
Qt do not use wchar_t* for Unicode strings as usual. Only QString or char*. If you want to contvert QString -> char* (or char* -> QString) use QTextCodec.
For example, older versions of Windows has encoding cp866
for console and if you want send unicode QString into command line:
QString string = "Unicode text";
QTextCodec *codec = QTextCodec::codecForName("cp866");
QByteArray encodedString = codec->fromUnicode(string);
//encodedString.data() - char* representation of unicode QString
For reading input parameters in main()
convert like this:
QTextCodec *codec = QTextCodec::codecForName("cp866");
QString strArg = codec->toUnicode(argv);
I think you should mentionQChar*
, which is the direct Qt alternative towchar_t*
.
– MSalters
Nov 22 at 14:26
1
Also note that code page 866 is Cyrillic; it's the default on a very small number of PC's worldwide.
– MSalters
Nov 22 at 15:06
add a comment |
up vote
-1
down vote
Qt do not use wchar_t* for Unicode strings as usual. Only QString or char*. If you want to contvert QString -> char* (or char* -> QString) use QTextCodec.
For example, older versions of Windows has encoding cp866
for console and if you want send unicode QString into command line:
QString string = "Unicode text";
QTextCodec *codec = QTextCodec::codecForName("cp866");
QByteArray encodedString = codec->fromUnicode(string);
//encodedString.data() - char* representation of unicode QString
For reading input parameters in main()
convert like this:
QTextCodec *codec = QTextCodec::codecForName("cp866");
QString strArg = codec->toUnicode(argv);
I think you should mentionQChar*
, which is the direct Qt alternative towchar_t*
.
– MSalters
Nov 22 at 14:26
1
Also note that code page 866 is Cyrillic; it's the default on a very small number of PC's worldwide.
– MSalters
Nov 22 at 15:06
add a comment |
up vote
-1
down vote
up vote
-1
down vote
Qt do not use wchar_t* for Unicode strings as usual. Only QString or char*. If you want to contvert QString -> char* (or char* -> QString) use QTextCodec.
For example, older versions of Windows has encoding cp866
for console and if you want send unicode QString into command line:
QString string = "Unicode text";
QTextCodec *codec = QTextCodec::codecForName("cp866");
QByteArray encodedString = codec->fromUnicode(string);
//encodedString.data() - char* representation of unicode QString
For reading input parameters in main()
convert like this:
QTextCodec *codec = QTextCodec::codecForName("cp866");
QString strArg = codec->toUnicode(argv);
Qt do not use wchar_t* for Unicode strings as usual. Only QString or char*. If you want to contvert QString -> char* (or char* -> QString) use QTextCodec.
For example, older versions of Windows has encoding cp866
for console and if you want send unicode QString into command line:
QString string = "Unicode text";
QTextCodec *codec = QTextCodec::codecForName("cp866");
QByteArray encodedString = codec->fromUnicode(string);
//encodedString.data() - char* representation of unicode QString
For reading input parameters in main()
convert like this:
QTextCodec *codec = QTextCodec::codecForName("cp866");
QString strArg = codec->toUnicode(argv);
edited Nov 22 at 14:17
answered Nov 22 at 14:12
Serhiy Kulish
923
923
I think you should mentionQChar*
, which is the direct Qt alternative towchar_t*
.
– MSalters
Nov 22 at 14:26
1
Also note that code page 866 is Cyrillic; it's the default on a very small number of PC's worldwide.
– MSalters
Nov 22 at 15:06
add a comment |
I think you should mentionQChar*
, which is the direct Qt alternative towchar_t*
.
– MSalters
Nov 22 at 14:26
1
Also note that code page 866 is Cyrillic; it's the default on a very small number of PC's worldwide.
– MSalters
Nov 22 at 15:06
I think you should mention
QChar*
, which is the direct Qt alternative to wchar_t*
.– MSalters
Nov 22 at 14:26
I think you should mention
QChar*
, which is the direct Qt alternative to wchar_t*
.– MSalters
Nov 22 at 14:26
1
1
Also note that code page 866 is Cyrillic; it's the default on a very small number of PC's worldwide.
– MSalters
Nov 22 at 15:06
Also note that code page 866 is Cyrillic; it's the default on a very small number of PC's worldwide.
– MSalters
Nov 22 at 15:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432448%2fpass-unicode-arguments-to-qapplication%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Either, you use
main()
instead or you "translate"wchar_t
s tochar
s. I cannot imagine thatQApplication
expects command line arguments where non-ASCII values are relevant but actually I'm not sure. File paths would be the exception.– Scheff
Nov 22 at 13:53
IIRC
QApplication::arguments
on Windows is already Unicode-aware. Write portable code, usingint main(int argc, char**argv)
and Qt will magically make it work.– MSalters
Nov 22 at 14:29
1
according to this answer the constructor argumenrt are not used to construct
QApplication::arguments()
. So you could as well not bother.– max630
Nov 25 at 8:38