LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-28-2007, 10:12 AM   #1
ManuPeng
Member
 
Registered: Mar 2006
Location: Germany
Distribution: OpenSuse 10.2
Posts: 54

Rep: Reputation: 15
How to use KArchive


Hi everyone,

I'm having trouble using the KArchive class to list the files contained in an archive. For now, I'm only trying to get it to compile, nothing more. Now, the class is virtual so I have to build a class based on it, but the constructor is being a pain somehow, so here's my derived class called Arch:
Code:
//This is arch.h

#include <qiodevice.h>
#include <karchive.h>

class Arch : public KArchive
{
public:
	Arch(QIODevice*);

    virtual bool writeDir( const QString& name, const QString& user, const QString& group );
    virtual bool prepareWriting( const QString& name, const QString& user, const QString& group, uint size );
    virtual bool doneWriting( uint size );
    virtual bool closeArchive();
    virtual bool openArchive( int mode );
};
The constructor of KArchive looks like this in karchive.h, it is "protected":
Code:
KArchive( QIODevice * dev );
This is arch.c:
Code:
//This is arch.c

#include "arch.h"

Arch::Arch(QIODevice*)
{

}
And now the code where I'm trying to use it:
Code:
#include <qlabel.h>
#include <qfile.h>

#include "testkzipwidget.h"
#include "arch.h"

testKZipWidget::testKZipWidget(QWidget* parent, const char* name, WFlags fl)
        : testKZipWidgetBase(parent,name,fl)
{}

testKZipWidget::~testKZipWidget()
{}

/*$SPECIALIZATION$*/
void testKZipWidget::button_clicked()
{
        //I know, this is not an archive but an image
        //Doesn't matter as I'm only trying to get it compile first
	QFile *file = new QFile("/home/manu/06.jpg");

	Arch *dummy = new Arch(file);
}
And finally the compiler / linker error messages:
Code:
/home/manu/projects/kdeprojects/testkzip/src/arch.cpp: In constructor ‘Arch::Arch(QIODevice*)’:
/home/manu/projects/kdeprojects/testkzip/src/arch.cpp:3: error: no matching function for call to ‘KArchive::KArchive()’
/opt/kde3/include/karchive.h:50: note: candidates are: KArchive::KArchive(QIODevice*)
/opt/kde3/include/karchive.h:43: note: KArchive::KArchive(const KArchive&)
gmake: *** [arch.o] Error 1
gmake: Target `testkzip' not remade because of errors.
*** Exited with status: 2 ***
Can anyone tell me what I'm doing wrong? I'd think my constructor looks OK since it seems to be the problem. Does anyone have a code sample on how to use that KArchive class?

Manu
 
Old 05-29-2007, 03:44 PM   #2
ManuPeng
Member
 
Registered: Mar 2006
Location: Germany
Distribution: OpenSuse 10.2
Posts: 54

Original Poster
Rep: Reputation: 15
Progress

Ok guys, there's a slight progress on my end, but still an error that I don't understand. For arch.h, see above in my first post, I changed the code in arch.cpp:
Code:
#include "arch.h"

Arch::Arch(QIODevice* dev) : KArchive(QIODevice* dev)
{
}
An now, the only error that remains is the following:
Code:
/home/manu/projects/kdeprojects/testkzip/src/arch.cpp: In constructor ‘Arch::Arch(QIODevice*)’:
/home/manu/projects/kdeprojects/testkzip/src/arch.cpp:3: error: expected primary-expression before ‘*’ token
gmake: *** [arch.o] Error 1
gmake: Target `testkzip' not remade because of errors.
*** Exited with status: 2 ***
I've tried moving the * around on the left of "dev" in both expressions and such but it still won't compile.

Any thoughts?
 
Old 05-31-2007, 03:00 PM   #3
ManuPeng
Member
 
Registered: Mar 2006
Location: Germany
Distribution: OpenSuse 10.2
Posts: 54

Original Poster
Rep: Reputation: 15
Alright, I got it all done by myself, the program compiles fine and even runs, now where I'm stuck is trying to find the proper way of using the methods as well as the correct order.

I have this code running but it tells me there are no entries / files within the archive, so my guess is, I either don't open the archive properly, or I need to initialize something before attempting to collect the entries. I guarantee I have two files / pictures in my archive, I made it myself and I can preview it using ark, all is fine.
The Arch object in the code snippet is my own class based on KArchive, it doesn't do anything beside forwarding everything to the KArchive methods.
Code:
QFile *file = new QFile("/home/manu/Archive.tar.gz");

Arch *dum = new Arch(file);
dum->open(IO_ReadOnly);

qDebug("Opened?: %i", dum->isOpened() );

const KArchiveDirectory *dir = dum->directory();

QStringList data = dir->entries();
qDebug("Count: %i", data.count() );
qDebug("isDirectory: %i", dir->isDirectory() );

for ( QStringList::Iterator it = data.begin(); it != data.end(); ++it )
{
	qDebug("File: %s", (*it).ascii() );
}
The output of the qDebug is:
Code:
Opened?: 1
Count: 0
isDirectory: 1
Count should be 2 to start with, and the qDebug within the For- loop never gets called because of that.

Any ideas? What am I doing wrong?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration