staticMetaObjectExtraData”: 不允许 dllimport 静态数据成员的定义

我是天下第一 2015-02-25 09:31:04
testManage.h
#ifndef TEST_MANAGE
#define TEST_MANAGE

#ifdef MYLIBDLL
#define MYLIBDLL_A _declspec(dllimport)
#else
#define MYLIBDLL_A _declspec(dllexport)
#endif

#endif


//////////////////
testdll1.h
#ifndef TESTDLL1_H
#define TESTDLL1_H

#include <QtGui/QMainWindow>
#include "ui_testdll1.h"
#include "testManage.h"
#include <string>
#include <iostream>
using namespace std;

class MYLIBDLL_A testDll1 : public QMainWindow
{
Q_OBJECT

public:
testDll1(QWidget *parent = 0, Qt::WFlags flags = 0);
~testDll1();

void printMe();
private:
Ui::testDll1Class ui;
};
#endif

////////////////////////////////
testdll.cpp
#include "testdll1.h"

testDll1::testDll1(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
}

testDll1::~testDll1()
{

}


void testDll1::printMe()
{
std::cout << "hello" << endl;
}

生成的时候,提示错误:
错误 5 error C2491: “testDll1::staticMetaObjectExtraData”: 不允许 dllimport 静态数据成员 的定义 E:\Projects\testDll1\testDll1\GeneratedFiles\Debug\moc_testdll1.cpp 47
错误 7 error C2491: “testDll1::staticMetaObject”: 不允许 dllimport 静态数据成员 的定义 E:\Projects\testDll1\testDll1\GeneratedFiles\Debug\moc_testdll1.cpp 51
我用的平台是vs2010. 好奇怪的问题啊。求同志们踊跃发言。哈哈哈
...全文
2135 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
我是传奇zhg 2016-10-21
  • 打赏
  • 举报
回复
3楼正解,如果有dll的源码,最好是自己重新用新版本编译一下,有高低版本问题也可以修改
qq_23849583 2016-06-07
  • 打赏
  • 举报
回复
testManage.h #ifndef TEST_MANAGE #define TEST_MANAGE #ifdef MYLIBDLL #define MYLIBDLL_A _declspec(dllimport) #else #define MYLIBDLL_A _declspec(dllexport) #endif #endif ////////////////// testdll1.h #ifndef TESTDLL1_H #define TESTDLL1_H #include <QtGui/QMainWindow> #include "ui_testdll1.h" #include "testManage.h" #include <string> #include <iostream> #include <QObject> using namespace std; class GsdQ_OBJECT:public QObject { Q_OBJECT public: //在这里加上你要用的信号,或者槽函数,否则编译不过 //用Q_OBJECT 的目的就是要使用信号或者槽函数 }; class MYLIBDLL_A testDll1 : public QMainWindow,public GsdQ_OBJECT { public: testDll1(QWidget *parent = 0, Qt::WFlags flags = 0); ~testDll1(); void printMe(); private: Ui::testDll1Class ui; }; #endif //////////////////////////////// testdll.cpp #include "testdll1.h" testDll1::testDll1(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { ui.setupUi(this); } testDll1::~testDll1() { } void testDll1::printMe() { std::cout << "hello" << endl; }
qq_23849583 2016-06-07
  • 打赏
  • 举报
回复
我也成功解决 testManage.h #ifndef TEST_MANAGE #define TEST_MANAGE #ifdef MYLIBDLL #define MYLIBDLL_A _declspec(dllimport) #else #define MYLIBDLL_A _declspec(dllexport) #endif #endif ////////////////// testdll1.h #ifndef TESTDLL1_H #define TESTDLL1_H #include <QtGui/QMainWindow> #include "ui_testdll1.h" #include "testManage.h" #include <string> #include <iostream> #include <QObject> using namespace std; class GsdQ_OBJECT:public QObject { Q_OBJECT public: }; class MYLIBDLL_A testDll1 : public QMainWindow,public GsdQ_OBJECT { public: testDll1(QWidget *parent = 0, Qt::WFlags flags = 0); ~testDll1(); void printMe(); private: Ui::testDll1Class ui; }; #endif //////////////////////////////// testdll.cpp #include "testdll1.h" testDll1::testDll1(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { ui.setupUi(this); } testDll1::~testDll1() { } void testDll1::printMe() { std::cout << "hello" << endl; }
cdsnghw 2016-04-19
  • 打赏
  • 举报
回复
我的解决过程: 假设原有QT3项目定义X类导出为X.lib,X.h: class export_qt_x X:public QObject { Q_Object X(); ~X(); ... } 当以此x.h和x.lib在Qt4中使用的时候,QT4和QT3对宏Q_OBJECT(定义一些成员)的定义不一样,导致QT4项目编译的时候,在x.lib中找不到QT4认为应该存在的成员,从而报告link error 此时,如果将x.h自定义编译生成 moc_x.cpp,则会生成部分成员和x.lib中同名,vc报告C2491 不要和dllinport定义同样的成员。 估计可以手动从moc_x.cpp中删除部分代码使得编译通过,或者Qt4项目删除class x中Q_object宏,但使用x.lib导入的类的内存布局,Qt3和Qt4不一定一样,因此有风险。 因此唯一的办法就是,将x.lib使用QT4重新生成(如果没有x.cpp,那除了冒着风险勉强编译通过,就没辙了)
cry1993 2015-05-26
  • 打赏
  • 举报
回复
楼主最后解决了吗,我也碰到这种问题了
xia910xx 2015-02-26
  • 打赏
  • 举报
回复
库只有导出 没有导入

16,212

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧