PDA

View Full Version : How to save?



merry
12th March 2007, 10:20
Hi all

I m working on Qt3.1 for Red Hat Linux, having a listview of items,
Now what I want is when I pressed upon save button of the MainWindow than the items that are checked in the listview must be saved at the path that is selected by me using filedialog;

Thanx

vermarajeev
12th March 2007, 10:31
Hi all

I m working on Qt3.1 for Red Hat Linux, having a listview of items,
Now what I want is when I pressed upon save button of the MainWindow than the items that are checked in the listview must be saved at the path that is selected by me using filedialog;

Thanx

Put the items in a QList, Whenever you check an item in listView, put that item in QList. In this way QList contains all the items which are checked. Now when you say 'save', open a filedialog to get the path where you want to dump the items.

But by the way what do you have for listItems.????? Is it images???????

merry
12th March 2007, 10:48
Thanx 4 ur reply

Yes ListItems are directories and files which are represented by different images

Thanx

vermarajeev
12th March 2007, 12:28
Thanx 4 ur reply

Yes ListItems are directories and files which are represented by different images

Thanx

I dont know how you want the files and directories containing images to be saved but I have written a sample program which can help you to achieve your target.

Here is the code


bool myClass::outputSelectedListItems( QList* selectedListItems, QList* totalListItem )
{
if( ! selectedListItems->isEmpty() )
{
QListIterator it( totalListItem );
QListItem* r;
while( (r = it.current()) != 0 )
{
++it;
if( -1 != selectedRoutes->findRef( r ) )
{
//here you are sure what items are
//selected so output accordingly
}
}
return true;
}
else
{
return false;
}
}

Hope this helps

merry
12th March 2007, 12:55
Thanx for the reply


I m sending U the code Which I had written :


#include <qfiledialog.h>
#include <qlistview.h>
#include <qstring.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qstringlist.h>
#include<qmessagebox.h>
#include <qpixmap.h>
#include <qdir.h>
#include <qstringlist.h>


void Form1::init()
{
listView->setColumnWidth(1,0);
listView->header()->setResizeEnabled(false,1);
}

void Form1::fileOpen()
{
QListViewItem* root=new QListViewItem(listView);
m_source = QFileDialog::getExistingDirectory(
"/home/",
this,
"get existing directory",
"Choose a directory",
TRUE );
root->setText(0,m_source);
CreateDirTree(root,m_source);
init();
}

void Form1::CreateDirTree(QListViewItem *item,QString path)
{

QDir dir(path);
QDir dir1;

const QFileInfoList * dirs=dir.entryInfoList();
{
if(dirs)

{
QFileInfoListIterator it(*dirs);
QFileInfo * fileInfo;
while(fileInfo=it.current())
{
++it;

if(fileInfo->fileName() =="." || fileInfo->fileName() =="..")
;
else if (fileInfo->isDir())
{
QString FilePath;
FilePath =path +"/"+ fileInfo->fileName();
m_temp = new QListViewItem(item);
m_temp->setText(0,fileInfo->fileName());
m_temp->setPixmap(0,QPixmap("/root/qt/Tree/images/folderunchecked.png"));
CreateDirTree(m_temp,FilePath);
}

else
{
m_temp = new QListViewItem(item);
m_temp->setText(0,fileInfo->fileName());
m_temp->setPixmap(0,QPixmap("/root/qt/Tree/images/fileunchecked.png"));

}
}
}


connect ( listView ,SIGNAL(pressed(QListViewItem*)),this,SLOT(reverse _images(QListViewItem*)));
}

}
void Form1 :: reverse_images(QListViewItem* item)
{
const QPixmap *pixmap;
pixmap=item->pixmap (0);
QImage image;
image=pixmap->convertToImage ();
QImage *image1=new QImage("/root/qt/Tree/images/folderunchecked.png");
QImage *image2=new QImage("/root/qt/Tree/images/folderchecked.png");
QImage *image3=new QImage("/root/qt/Tree/images/fileunchecked.png");
QImage *image4=new QImage("/root/qt/Tree/images/filechecked.png");

if(image1->operator==(image)==true)
{
item->setPixmap(0,QPixmap("/root/qt/Tree/images/folderchecked.png"));
}
else if(image2->operator==(image)==true)
{
item->setPixmap(0,QPixmap("/root/qt/Tree/images/folderunchecked.png"));
}
else if(image3->operator==(image)==true)
{
item->setPixmap(0,QPixmap("/root/qt/Tree/images/filechecked.png"));
}
else if(image4->operator==(image)==true)
{
item->setPixmap(0,QPixmap("/root/qt/Tree/images/fileunchecked.png"));
}


}




This is the code with which I got the listview of the items(files and folders) and also can checked ,unchecked the items. Now what I want is that when I click on the save button of the filemenu ->then all the checked items mustbe saved .


thanx

vermarajeev
12th March 2007, 13:39
Thanx for the reply


I m sending U the code Which I had written :




This is the code with which I got the listview of the items(files and folders) and also can checked ,unchecked the items. Now what I want is that when I click on the save button of the filemenu ->then all the checked items mustbe saved .


thanx

Take a QList<QListItem*> totalListItem and QList<QListItem*>selectedListItem. I assume that you know what is the total listItem displayed, put these items into totalListItem.
I'm too assuming that when you check any listItem this fuction gets called


reverse _images(QListViewItem*)

If that is the case then whenever you call reverse _images(QListViewItem*) function insert the selected item into selectedListItem. Then finally write a function called file save to save the images. Use the above defined function to save the images (defined in above post)

Hope this helps

merry
13th March 2007, 06:48
Hi

Thanx for the help But I m working on Qt3.1 , in this ther is no function "QList"
Can we save this by using the concept of linked list , If yes then pls tell me how bcoz i never used linked list before.


Thanx

wysota
13th March 2007, 07:56
Use QPtrList or QValueList instead.