QT中的易犯小错误

转载自:http://blog.csdn.net/qianguozheng/article/details/6711997

1。继承QWidget是要用public 。

2。构造函数也要是public。

3。构造函数的参数 初始化parent=0。

4。头文件声明了,源文件就要初始化。




  1. #include<QtGui/QtGui>  
  2. class QLabel;  
  3. class QLineEdit;  
  4. class QPushButton;  
  5. class QWidget;  
  6.   
  7. class InputDlg :<span style="color:#FF0000;">public</span> QWidget  
  8. {  
  9.   Q_OBJECT  
  10. public:  
  11. <span style="color:#FF0000;">  InputDlg(QWidget *parent=0);  
  12.   ~InputDlg();</span>  
  13. public:  
  14.   
  15.   QLabel *namelabel;  
  16.   QLabel *sexlabel;  
  17.   QLabel *agelabel;  
  18.   QLabel *heightlabel;  
  19.   QLineEdit *name;  
  20.   QLineEdit *sex;  
  21.   QLineEdit *age;  
  22.   QLineEdit *height;  
  23.   QPushButton *addname;  
  24.   QPushButton *addsex;  
  25.   QPushButton *addage;  
  26.   QPushButton *addheight;  
  27.   
  28. private slots:    
  29.   void slotName();  
  30.   void slotSex();  
  31.   void slotAge();  
  32.   void slotHeight();  
  33. };  



5。出现诸如下面的错误

  1. In file included from main.cpp:2:  
  2. /usr/include/qt4/QtGui/qwidget.h: <span style="color:#FF0000;">In copy constructor ‘InputDlg::InputDlg(const InputDlg&)’:</span>  
  3. /usr/include/qt4/QtGui/qwidget.h:782: error: <span style="color:#FF0000;">‘QWidget::QWidget(const QWidget&)’ is private</span>  

问题在于调用InputDlg声明的要是指针

  1. InputDlg *dlg=new InputDlg;  

6。

  1. button.h:10: error: invalid use of incomplete type ‘struct QPushButton’  
  2. button.h:4: error: forward declaration of ‘struct QPushButton’  
添加 #include <QtGui/QtGui>

问题解决了。。不过究竟是什么原因呢?


7。

数据库找不到头文件

在项目文件中加入

QT+=sql

8。

网络程序找不到头文件

在项目文件中加入

QT+=network

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值