user3639779
user3639779

Reputation: 79

QString to char*

I am trying to convert QString into char*. The code that i have been using is

QString username = useradd->text();
QByteArray un=username.toLatin1();
const char *str = un.data();

Where useradd is the name given to "lineedit"

On compilation the following error occurs

class QString has no member named toLatin1

Upvotes: 0

Views: 1236

Answers (2)

phyatt
phyatt

Reputation: 19152

If you are using only once, like in a debug line, use this:

http://qt-project.org/doc/qt-4.8/qtglobal.html#qPrintable

This is equivalent to str.toLocal8Bit().constData().

qDebug() << qPrintable(myString);

Upvotes: 0

Ivan
Ivan

Reputation: 499

This way: QString::toStdString()::c_str()

Upvotes: 1

Related Questions