Proper QUuid usage in Qt ? (7-Zip DLL usage proble

2019-08-25 17:47发布

问题:

I'm trying to write a program that would use 7-Zip DLL for reading files from inside archive files (7z, zip etc).

Here's where I'm so far:

#include <QtCore/QCoreApplication>
#include <QLibrary>
#include <QUuid>
#include <iostream>

using namespace std;  

#include "7z910/CPP/7zip/Archive/IArchive.h"
#include "7z910/CPP/7zip/IStream.h"
#include "MyCom.h"

// {23170F69-40C1-278A-1000-000110070000}  
QUuid CLSID_CFormat7z(0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);  

typedef int (*CreateObjectFunc)(  
 const GUID *clsID,  
 const GUID *interfaceID,  
 void **outObject);  

void readFileInArchive()  
{  
 QLibrary myLib("7z.dll");  
 CreateObjectFunc myFunction = (CreateObjectFunc)myLib.resolve("CreateObject");  
 if (myFunction == 0) {  
  cout << "CreateObject resolve failed!";  
  return;  
 }  
 else {  
  cout << "CreateObject resolved";  
 }  
 CMyComPtr<IOutArchive> outArchive;  
 myFunction(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive);  
}  

int main(int argc, char *argv[])  
{  
 QCoreApplication a(argc, argv);  
 readFileInArchive();  
 return a.exec();  
}  

Trying to build that in Qt Creator will lead to following error:

cannot convert 'QUuid*' to 'const GUID*' in argument passing

How should QUuid be correctly used in this context?

Also, being a C++ and Qt newbie I haven't yet quite grasped templates or interfaces, so overall I'm having trouble getting through these first steps. If someone could give tips or even example code on how for example an image file could be extracted from ZIP file (to be shown in Qt GUI later on*), I would highly appreciate that.

  • My main goal at the moment is to write a program with GUI for selecting archive files containing image files (PNG, JPG etc) and displaying those files one at a time in the GUI. A Qt based CDisplayEx in short.

回答1:

You have to explicitly cast QUuid to GUID:

QUuid boo;
GUID uid = static_cast<GUID>(boo);


回答2:

You must use some conversion between the 2 types.

Looking at Qt documentation, I found that there is a GUID operator that transform a QUuid to a Windows GUID : http://doc.trolltech.com/4.6/quuid.html#operator-GUID

Of course, this is not cross-plateform.