[SOLVED] Converting from QString to char
-
Hello everybody! help please! I have no idea how to do.
I need to convert QString, it means ui->lineEdit->text() to char, means char expr[255]? How to do it without using const char or char * or QByteArray? -
QString::latin1() to have const char *. If you want you can download the source of QtComPort (http://kde-apps.org/content/show.php/?content=142378) and look at the file qcserialcomport.cpp to have some conversion functions.
Bye bye.
-
unfortunately i have windows ( not linux
-
[quote author="mrdebug" date="1379700265"]QString::latin1() to have const char *. If you want you can download the source of QtComPort (http://kde-apps.org/content/show.php/?content=142378) and look at the file qcserialcomport.cpp to have some conversion functions.
Bye bye.[/quote]
unfortunately i have windows not linux -
It' the same. The program works on Linux and Windows. Look ad my website for have a Windows version. Look at the qcserialcomport.cpp file to see how is possibile to convert string to char.
-
Why don't you want to use a QByteArray? It's very convenient.
@
char expr[255];
QString string = ...if (string.length() < 255) {
QByteArray ba = string.toLocal8Bit();
strcpy(expr, ba.constData());
} else {
qWarning("String is too long!");
}
@ -
[quote author="JKSH" date="1379719254"]Why don't you want to use a QByteArray? It's very convenient.
@
char expr[255];
QString string = ...if (string.length() < 255) {
QByteArray ba = string.toLocal8Bit();
strcpy(expr, ba.constData());
} else {
qWarning("String is too long!");
}
@[/quote]the problem is solved :) thanks everybody for help! :)