[英]C2059: syntax error : 'public' in Qt
I was getting this error which was driving me crazy. 我遇到了这个错误,这使我发疯。 I just added a class using Qt Creator but it will not build. 我刚刚使用Qt Creator添加了一个类,但无法构建。
#ifndef LIBRARY_H
#define LIBRARY_H
class Library
{
public:
Library();
signals:
public slots:
};
#endif // LIBRARY_H
The errors are: 错误是:
library.h:12: error: C2059: syntax error : 'public'
library.h:12: error: C2334: unexpected token(s) preceding ':'; skipping apparent function body
library.h:13: error: C2760: syntax error : expected '{' not '}'
library.h:13: error: C2143: syntax error : missing '}' before ';'
library.cpp:4: error: C2535: 'Library::Library(void)' : member function already defined or declared
library.cpp:8: error: C1004: unexpected end-of-file found
The problem was Qt Creator added signal
and slots
even though I added a C++ class (as opposed to Qt class) and didn't derive it from QObject
. 问题是即使我添加了C ++类(与Qt类相对)并且没有从QObject
派生它,Qt Creator还是添加了signal
和slots
。
The solution is to remove signal
and slots
words from the class or derive it from QObject
and #include <QObject>
解决方案是从类中删除signal
和slots
词,或者从QObject
和#include <QObject>
派生它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.