当前位置:   article > 正文

QT中的易犯小错误_qt qss报错in file included from ..\untitled1\mainwin

qt qss报错in file included from ..\untitled1\mainwindow.cpp:2:0:

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. class InputDlg :public QWidget
  7. {
  8. Q_OBJECT
  9. public:
  10. InputDlg(QWidget *parent=0);
  11. ~InputDlg();
  12. public:
  13. QLabel *namelabel;
  14. QLabel *sexlabel;
  15. QLabel *agelabel;
  16. QLabel *heightlabel;
  17. QLineEdit *name;
  18. QLineEdit *sex;
  19. QLineEdit *age;
  20. QLineEdit *height;
  21. QPushButton *addname;
  22. QPushButton *addsex;
  23. QPushButton *addage;
  24. QPushButton *addheight;
  25. private slots:
  26. void slotName();
  27. void slotSex();
  28. void slotAge();
  29. void slotHeight();
  30. };



5。出现诸如下面的错误

  1. In file included from main.cpp:2:
  2. /usr/include/qt4/QtGui/qwidget.h: In copy constructor ‘InputDlg::InputDlg(const InputDlg&)’:
  3. /usr/include/qt4/QtGui/qwidget.h:782: error: ‘QWidget::QWidget(const QWidget&)’ is private

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/201184
推荐阅读
相关标签
  

闽ICP备14008679号