hi ,

My problem is , How to get std::string object from a QString in Qt 3

What i did :-
1) I have a binary/text file.
2) I stored the data in QByteArray
3) I created a QString from QByteArray

What am trying to achieve :-
1) I am trying to create a std::string object( for seding the object to an ENCRPTIONFUNCTION ) from QString
2) In Qt 4.2.2 am able to get a std::string from QString.
But how can i make it work in Qt3.

See the code below ( in Qt 4) . Please help me to work the same in Qt3..

Qt Code:
  1. #include <QMessageBox>
  2. #include <QIODevice>
  3. #include <QFile>
  4. #include <QByteArray>
  5. #include <QString>
  6. #include <QtDebug>
  7.  
  8.  
  9. //FOR standard C++ libraries.
  10. #include <ios>
  11. #include <iostream>
  12. #include <string>
  13. using namespace std;
  14.  
  15. int main(int argc, char *argv[])
  16. {
  17. QByteArray byteArray;
  18. QFile f ( "m1_enc.ct" ); //binary file encoded using CBC Mode.
  19. //QFile f ( "m1.ct" ); //Text file
  20. //QFile f ( "Feb.ct"); //Text file
  21.  
  22. if ( f.open ( QIODevice::ReadOnly ) )
  23. {
  24. // file opened successfully
  25. byteArray = f.readAll();
  26. }
  27. else
  28. {
  29. // problems opening the file - emit a warning message
  30. QMessageBox::warning( 0, QObject::tr("error"),
  31. QObject::tr("Error opening file %1") ) ;
  32. return -1;
  33. }
  34. f.close();
  35. Q_ASSERT( ! byteArray.isEmpty() );
  36.  
  37. //CASE_1
  38. qDebug() << "QString from Binary_Data( QByteArray ) \n\n" << QString(byteArray) ;
  39.  
  40. //CASE_2
  41. qDebug() << "Binary_Data(QByteArray) from QString \n\n" << QString(byteArray).toLatin1();
  42.  
  43.  
  44. //CASE_3
  45. string str = QString(byteArray).toStdString() ;
  46.  
  47. // string strFromQString( str );
  48. qDebug() << "String from QString \n\n" << str.data();
  49.  
  50.  
  51. return 0;
  52.  
  53. }
To copy to clipboard, switch view to plain text mode 

thanks in advance.