Qt 中 QUuid 的正确使用? (7-Zip DLL使用问题(QLibrary、QUuid GUID转换、接口))

发布于 2024-08-29 08:20:49 字数 1530 浏览 2 评论 0原文

我正在尝试编写一个程序,该程序将使用 7-Zip DLL 从存档文件(7z、zip 等)内部读取文件。

到目前为止,我的情况如下:

#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();  
}  

尝试在 Qt Creator 中构建它会导致以下错误:

无法在参数传递中将“QUuid*”转换为“const GUID*”

在这种情况下应该如何正确使用 QUuid?

另外,作为一个 C++ 和 Qt 新手,我还没有完全掌握模板或接口,所以总的来说,我在完成这些第一步时遇到了困难。如果有人可以提供提示甚至示例代码,说明如何从 ZIP 文件中提取图像文件(稍后将在 Qt GUI 中显示*),我将非常感激。

  • 我目前的主要目标是编写一个带有 GUI 的程序,用于选择包含图像文件(PNG、JPG 等)的存档文件,并在 GUI 中一次显示一个文件。简而言之,基于 Qt 的 CDisplayEx。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小镇女孩 2024-09-05 08:20:49

您必须显式地将 QUuid 转换为 GUID:

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

You have to explicitly cast QUuid to GUID:

QUuid boo;
GUID uid = static_cast<GUID>(boo);
仅此而已 2024-09-05 08:20:49

您必须在两种类型之间使用某种转换。

查看 Qt 文档,我发现有一个 GUID 运算符可以将 QUuid 转换为 Windows GUID : http://doc.trolltech.com/4.6/quuid.html#operator-GUID

当然,这不是跨平台的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文