Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 关于QPlugin的一点小问题。
Forum Updated to NodeBB v4.3 + New Features

关于QPlugin的一点小问题。

Scheduled Pinned Locked Moved Unsolved Chinese
1 Posts 1 Posters 215 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr.black
    wrote on last edited by
    #1

    最近要做一个可动态加载的插件,由于后面可能要跨平台,因此打算用QtPlugin来实现,结果刚起步就遇到一个坑。具体情况如下:
    写了一个接口文件,命名为interface.h:
    #pragma once
    #include <QtPlugin>
    struct AAA
    {
    AAA() {}
    virtual ~AAA() {}
    virtual void test() = 0;
    };

    #define AAA_iid "TEST.AAA"

    Q_DECLARE_INTERFACE(AAA, AAA_iid)

    紧接着写它的派生类文件BBB.h
    #include "interface.h"
    class BBB: public QObject, public AAA
    {
    Q_OBJECT
    Q_PLUGIN_METADATA(IID AAA_iid)
    Q_INTERFACES(AAA)
    public:
    BBB();
    ~BBB() {}
    void test() { }
    };
    BBB.cpp也是存在的,但里面是空的。

    看似都没有问题,此时点击生成,结果编译报错:
    Parse error at "IID"

    被折磨一天之后,发现只要interface.h文件放在其他目录下,和第三方文件一样包含进来就会出这个错。将其拷贝到工程目录下,和工程里派生类放一起,这个问题就会消失。看着就很奇怪,有没有人知道是为啥?

    我的环境是vs2017,用的qt是5.9和5.12(问题一样,我还试了网上说的更换qt vs tools,完全没效果)

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved