--- Begin Message ---
Hi Svenn
Saw ur problem for Address Book. Actually I am also implementing an address book in whcih I am storing User name, Phone Number and Photo of the user. I am using a Structure Triplet for it. M pasting the code of what I am doing.
///////////////////////////////////////////////////////// Start ////////////////////////////////////////////////////////////////
const char* dataFile = "names.dat";
struct Triplet
{
QString name;
QString phone;
QString image;
};
void MainWindow::load()
{
QFile ifile(dataFile);
if(!ifile.open(QIODevice::ReadOnly))
{
QMessageBox::warning(this,tr("Error"),tr("File can't be opened for reading."),QMessageBox::Ok,0);
return;
}
QDataStream ds(&ifile);
ds.setVersion(QDataStream::Qt_4_1);
QListWidgetItem *lwt;
int x;
ds>>x;
while(!ds.atEnd())
{
lwt = new MyListItem();
lwt->read(ds);
listing.addItem(lwt);
}
ifile.close();
}
void MainWindow::write()
{
QFile ofile(dataFile);
if(!ofile.open(QIODevice::WriteOnly))
{
QMessageBox::warning(this,tr("Error"),tr("File can't be opened for writing."),QMessageBox::Ok,0);
return;
}
QDataStream ds(&ofile);
ds.setVersion(QDataStream::Qt_4_1);
QListWidgetItem *lwt;
int c = listing.count();
ds<<c;
for(int i = 0; i<c; i++)
{
lwt = listing.item(i);
lwt->write(ds);
}
ofile.close();
}
void MainWindow::addName()
{
Triplet *t = DispDialog::getData(this,NULL);
if(t==NULL)
return;
MyListItem *lwt = new MyListItem();
lwt->setText((t->name)+"\n"+(t->phone));
lwt->setIcon(QIcon(t->image));
lwt->setBackgroundColor(QColor(255,255,255));
lwt->setTextColor(QColor(255,0,0));
lwt->name=t->name;
lwt->phone=t->phone;
lwt->image=t->image;
listing.addItem(lwt);
delete t;
}
AND
void MyListItem::read(QDataStream &in)
{
in>>name;
in>>phone;
in>>image;
QListWidgetItem::read(in);
}
void MyListItem::write(QDataStream &out) const
{
out<<name;
out<<phone;
out<<image;
QListWidgetItem::write(out);
}
////////////////////////////////////////////////////////// End //////////////////////////////////////////////////////
THIS CODE WORKED FINE till QT was configured as Dynamic build. But due to some requirement (running exe on PC where QT is not installed), I configured it as -
C:\Qt\4.1.1>configure -debug -static -qt-gif -system-libjpeg
and then wrote a code to display images as -
In "Main.cpp" ->
#include <QtPlugin>
Q_IMPORT_PLUGIN(qjpeg)
Q_IMPORT_PLUGIN(qgif)
In ".pro" file
QTPLUGIN += qjpeg qgif qmng
And in "Makefile.Debug" ->
QMAKE_LFLAGS += -L$$[QT_INSTALL_PLUGINS]/imageformats
The problem is that now it terminates the program whenever I call the Write or Load function which saves the Images!! The Write function includes the image in the data base but after hat application terminates. Where as the Load function loads the application but doesn't display the images.
Can u plzz help me to figure out what actually i have done wrong.
Thanks in advance
Regards,
Ritzz
India
Svenn Are Bjerkem <svenn.bjerkem@xxxxxxxxxxxxxx> wrote:
On 7/10/07, Svenn Are Bjerkem wrote:
> Hi,
---------------------------------
Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
--- End Message ---