【发布时间】:2011-12-09 21:01:54
【问题描述】:
我有
class Foo : public QFrame {...}
在使用这个类的模块中,我有
QWidget* screen = this->parentWidget();
Foo* foo = (Foo*) screen->findChild<QFrame*>("foo1"); // foo1 is the name of the control from .ui file
这行得通。如果我把它改成
QWidget* screen = this->parentWidget();
Foo* foo = screen->findChild<Foo*>("foo1"); // foo1 is the name of the control from .ui file
我收到此链接器错误
错误 4 错误 LNK2001: 无法解析的外部符号 "public: static 结构 QMetaObject const Foo::staticMetaObject" (?staticMetaObject@Foo@@2UQMetaObject@@B) Foo.obj
这两个sn-ps有什么区别,为什么第一个有效而第二个无效?
【问题讨论】:
-
它们在 C++ 中被称为“模板”。
-
旁注,在 C++ 中它们不被称为泛型。这些是模板。
-
并不是说它们不被称为泛型。它们不是泛型。根本区别之一是我们在这个问题中看到的行为。
-
@RobKennedy:哦,完全。如果您知道某事的叫什么,则搜索有关某事的帮助会容易得多。