• 9596阅读
  • 4回复

[提问]expected class-name before '{' token [复制链接]

上一主题 下一主题
离线wlcl
 
只看楼主 倒序阅读 楼主  发表于: 2011-12-04
笔者,正在进行QT学习。。。。
在练习对话框程序的时候,出现了
expected class-name before '{' token
错误。。 不知道为什么。
现将系统信息贴出来


#10#caopeng@laptop ~]$qmake --version

QMake version 2.01aUsing Qt version 4.6.2 in /usr/lib
[#11#caopeng@laptop ~]$g++ --version

g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[#12#caopeng@laptop ~]$uname -a

Linux laptop 2.6.32-24-generic #43-Ubuntu SMP Thu Sep 16 14:17:33 UTC 2010 i686 GNU/Linux        
[#13#caopeng@laptop ~]$qtcreator -version

Qt Creator 1.3.1 based on Qt 4.6.2  BinEditor 1.3.1 Binary editor component.
  Bookmarks 1.3.1 Bookmarks in text editors.  CMakeProjectManager 1.3.1 CMake support
  CVS 1.3.1 CVS integration.  CodePaster 1.3.1 Codepaster plugin for pushing/fetching diff from server
  Core 1.3.1 The core plugin for the Qt IDE.  CppEditor 1.3.1 C/C++ editor component.
  CppTools 1.3.1 Tools for analyzing C/C++ code.  Debugger 1.3.1 Debugger integration.
  Designer 1.3.1 Qt Designer integration.  FakeVim 1.3.1 VI-style keyboard navigation.
  Find 1.3.1 Provides the find widget and the hooks for find implementations.  GenericProjectManager 1.3.1 Generic support
  Help 1.3.1 Help system.  Locator 1.3.1 Provides the Locator widget and the hooks for Locator filter implementations.
  Perforce 1.3.1 Perforce integration.  ProjectExplorer 1.3.1 ProjectExplorer framework that can be extended with different kind of project types.
  QmlEditor 1.3.1 Editor for QML.  QmlProjectManager 1.3.1 Qml support
  Qt4ProjectManager 1.3.1 Provides project type for Qt 4 pro files and tools.  QtScriptEditor 1.3.1 Editor for QtScript.
  ResourceEditor 1.3.1 Editor for qrc files.  ScmGit 1.3.1 Git integration.
  Subversion 1.3.1 Subversion integration.  TextEditor 1.3.1 Text editor framework and the implementation of the basic text editor.
  VCSBase 1.3.1 Version Control System Base Plugin  Welcome 1.3.1 Default Welcome Screen Plugin
[#14#caopeng@laptop ~]$

有一个listCardDialog.ui文件


然后,在listCardDialog.h 当中由如下代码。。

#ifndef LISTCARDDIALOG_H
#define LISTCARDDIALOG_H
#include <QDialog>
#include "ui_listCardDialog.h"
class ListCardDialog : public QDialog , public Ui::ListCardDialog
{                   //错误提示在改行。。。
    Q_OBJECT
public:
    ListCardDialog(QWidget *parent = 0);
private slots:
    void comboBoxChanged();
};
#endif // LISTCARDDIALOG_H
其他的cpp文件,步一一贴出。。。
编译的时候,就会出现
expected class-name before '{' token
的错误
离线wxj120bw

只看该作者 1楼 发表于: 2011-12-05
回 楼主(wlcl) 的帖子
下面的代码是qt creator自动生成 还是你自己写的
  1. class ListCardDialog : public QDialog , public Ui::ListCardDialog
  2. {  
离线ninsun

只看该作者 2楼 发表于: 2011-12-05
qmake一下试试?
可能是Ui::ListCardDialog这个类没有被uic生成的原因吧..
离线wlcl
只看该作者 3楼 发表于: 2011-12-05
回 1楼(wxj120bw) 的帖子
已经找到问题所在了。
不知道为何,.ui文件生成的是.h文件内容是这样的
class Ui_ListCardDialog
{
。。。。。。
};
修改以下继承关系,就好了。
但是,不明白,为什么是
class Ui_ListCardDialog
而不是
class Ui::ListCardDialog
离线roywillow

只看该作者 4楼 发表于: 2011-12-05
回 3楼(wlcl) 的帖子
我觉得这也没什么为什么吧……
ui的h文件中有一个Ui_XXX类,这个类大概直接用来多继承会比较方便
然后又会生成一个Ui名称空间,里面用XXX又继承了一遍Ui_XXX,这个应该是成员变量实例化来创建ui的时候比较好用

话说还从来没试过继承某个namespace中的类,你可以自己写一个测试代码试试?
专业维修核潜艇,回收二手航母、二手航天飞机,大修核反应堆,拆洗导弹发动机更换机油,无人侦察机手动挡改自动,航天飞机保养换三滤,飞碟外太空年检 ,各型号导弹加装迎宾踏板,高空作业擦洗卫星表面除尘、打蜡及抛光,东风全系列巡航导弹。并提供原子对撞机。量大从优,有正规发票。
快速回复
限100 字节
 
上一个 下一个