Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
Posts: 37
Registered: ‎07-13-2014
My Device: Z10
My Carrier: Vodafone

Serializing Message class in blackberry cascades

Hi All,

 

I have a QList<Message> which has messages in it.

 

I wish to save it to file and as per related link:-

 

http://supportforums.blackberry.com/t5/Native-Development/Write-QList-lt-Message-gt-to-file/td-p/293...

 

need is there to serialize it.

 

Will a simple serialization code below:

 

Message message; 
................
................
QFile file("file.dat");
    file.open(QIODevice::WriteOnly);

    QDataStream out(&file);   // we will serialize the data into the file
    out <<message;

 

Or some changes needs to be done in order to serialize the Message.

 

The intent here is to store QList<Messages> into file and later parse it in another blackberry devices.

 

Please suggest 

 

Thanks & Regards

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Serializing Message class in blackberry cascades

where is the difference to your older question in
http://supportforums.blackberry.com/t5/Native-Development/Write-QList-lt-Message-gt-to-file/td-p/293...
?

you still need to implement the serialization yourself, i already gave you some links in your previous thread.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 37
Registered: ‎07-13-2014
My Device: Z10
My Carrier: Vodafone

Re: Serializing Message class in blackberry cascades

I have tried below code snippet for serialising Message .

 

bool Messages::serializeMessages() {

	bool successFlag = false;
	QDir dir;
	bb::device::SdCardInfo sDCardInfo;
	if(sDCardInfo.state() == bb::device::SdCardState::Mounted)
	{
		dir.cd("/accounts/1000/removable/sdcard/");
		dir.mkdir("messages");
	}
	QFile myFile("/accounts/1000/removable/sdcard/messages/vCardMessages.dat");

	if(myFile.open(QIODevice::WriteOnly)) {
		QDataStream out(&myFile);
		// Iterate through all the messages and convert it into data stream
		foreach (const Message &message, inboxMessages) {
			out << message;
		}
	}
	return successFlag;
}

 

This is giving error at line  

out << message;

 

Please suggest what error is there.

 

Thanks & Regards,

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Serializing Message class in blackberry cascades

the message class does not support the << operator. you will have to implement that functionality yourself.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter