joseph
14th August 2007, 11:53
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..
#include <QMessageBox>
#include <QIODevice>
#include <QFile>
#include <QByteArray>
#include <QString>
#include <QtDebug>
//FOR standard C++ libraries.
#include <ios>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
QByteArray byteArray;
QFile f ( "m1_enc.ct" ); //binary file encoded using CBC Mode.
//QFile f ( "m1.ct" ); //Text file
//QFile f ( "Feb.ct"); //Text file
if ( f.open ( QIODevice::ReadOnly ) )
{
// file opened successfully
byteArray = f.readAll();
}
else
{
// problems opening the file - emit a warning message
QMessageBox::warning( 0, QObject::tr("error"),
QObject::tr("Error opening file %1") ) ;
return -1;
}
f.close();
Q_ASSERT( ! byteArray.isEmpty() );
//CASE_1
qDebug() << "QString from Binary_Data( QByteArray ) \n\n" << QString(byteArray) ;
//CASE_2
qDebug() << "Binary_Data(QByteArray) from QString \n\n" << QString(byteArray).toLatin1();
//CASE_3
string str = QString(byteArray).toStdString() ;
// string strFromQString( str );
qDebug() << "String from QString \n\n" << str.data();
return 0;
}
thanks in advance.
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..
#include <QMessageBox>
#include <QIODevice>
#include <QFile>
#include <QByteArray>
#include <QString>
#include <QtDebug>
//FOR standard C++ libraries.
#include <ios>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
QByteArray byteArray;
QFile f ( "m1_enc.ct" ); //binary file encoded using CBC Mode.
//QFile f ( "m1.ct" ); //Text file
//QFile f ( "Feb.ct"); //Text file
if ( f.open ( QIODevice::ReadOnly ) )
{
// file opened successfully
byteArray = f.readAll();
}
else
{
// problems opening the file - emit a warning message
QMessageBox::warning( 0, QObject::tr("error"),
QObject::tr("Error opening file %1") ) ;
return -1;
}
f.close();
Q_ASSERT( ! byteArray.isEmpty() );
//CASE_1
qDebug() << "QString from Binary_Data( QByteArray ) \n\n" << QString(byteArray) ;
//CASE_2
qDebug() << "Binary_Data(QByteArray) from QString \n\n" << QString(byteArray).toLatin1();
//CASE_3
string str = QString(byteArray).toStdString() ;
// string strFromQString( str );
qDebug() << "String from QString \n\n" << str.data();
return 0;
}
thanks in advance.