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
  • 100,941
  • 24
  • 163
  • 252
user3639779
  • 69
  • 1
  • 9

2 Answers2

1

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

Ivan
  • 476
  • 1
  • 6
  • 20
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
  • 17,674
  • 5
  • 55
  • 73