0

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

haccks
  • 104,019
  • 25
  • 176
  • 264
user3639779
  • 79
  • 1
  • 9

2 Answers2

1

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

Ivan
  • 490
  • 1
  • 7
  • 23
0

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);
phyatt
  • 18,472
  • 5
  • 61
  • 80