C2059:语法错误:Qt 中的'public'
C2059: syntax error : 'public' in Qt
我遇到了这个错误,这让我抓狂。我刚刚用QtCreator添加了一个类,但它不会构建。
#ifndef LIBRARY_H
#define LIBRARY_H
class Library
{
public:
Library();
signals:
public slots:
};
#endif // LIBRARY_H
错误为:
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
问题是Qt Creator添加了signal
和slots
,尽管我添加了C++类(而不是Qt类),并且没有从QObject
派生它。
解决方案是从类中删除signal
和slots
单词,或从QObject
和#include <QObject>
派生
相关文章:
- Qt VTK交互风格的信号到小部件
- QT在错误的班级中寻找空位
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 如何在Qt C++中更改光标
- 如何在MS Visual Studio 2019中运行QT UI
- QT通过C++添加映射QML项目
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用Qt C++计算类似Git的SHA1哈希
- Qt focusObjectChanged example?
- 如何在cpp文件之间切换窗口?在Qt中
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- Qt和C++:将QLineEdit添加到QTabWidget中
- 从数据库实时显示QT c++中的数据
- Qt Quick-如何仅从c++代码与qml属性交互
- 无法使用Qt Creator在Windows中构建yaml-cpp
- C2059:语法错误:Qt 中的'public'
- Make QTimer public. (Qt, C++)