PDA

View Full Version : Getting const char * from QLineEdit



squidge
5th November 2009, 09:41
Is there an easy way of doing this? It seems that ui->TextEdit->text().toAscii().constData() returns garbage and on further investigation it seems to return a class that is freed before the method returns, so I have to assign it to a QByteArray first - QByteArray text = ui->TextEdit->text().toAscii()) and then use constData on that, which seems overly complicated for such a simple operation.

squidge
6th November 2009, 08:54
No one else has a solution for this? Copying to a QByteArray every time this is needed seems a little daft when other gui kits has simple things like c_str()

lyuts
9th November 2009, 10:28
1. Why do you need const char*?
2. yourLineEdit->text().toStdString().c_str();