代码报错。NO MATCHING FUNCTION CALL TO……
文件a.cpp在DEBUG的时候报错,下面是a.cpp的。然后 main 的就不列出了放不下。求高手解答。谢谢了
#include "widget.h"
Widget:: Widget(QWidget *parent)
: QWidget(parent)
{
//setMinimumSize( 200, 120 );
//setMaximumSize( 200, 120 );
// QPushButton *quit = new QPushButton( "Quit",this );
// quit->setGeometry( 62, 40, 75, 30 );
//quit->setFont( QFont( "Times", 18, QFont::Bold ) );
// connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
ui.setupUi(this); //有错误的一行
}
Widget::~Widget()
{
}
下面是 "widget.h"
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui/QWidget>
#include <qapplication.h>
#include <qpushbutton.h>
#include <qfont.h>
#include "ui.h"
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
private:
Ui::m_window ui;
};
#endif // WIDGET_H
下面是 "ui.h"
/********************************************************************************
** Form generated from reading UI file 'gkxt2uW4872.ui'
**
** Created: Fri Dec 31 12:17:38 2010
** by: Qt User Interface Compiler version 4.7.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef GKXT2UW4872_H
#define GKXT2UW4872_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
#include <QtGui/QScrollArea>
#include <QtGui/QScrollBar>
#include <QtGui/QStatusBar>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_m_window
{
public:
QAction *menu_start;
QAction *menu_exit;
QAction *action_3;
QAction *action_5;
QAction *action_6;
QAction *menu_sysset;
QAction *menu_queset;
QAction *menu_login;
QAction *menu_bbs;
QAction *menu_learn;
QAction *action_12;
QAction *action_14;
QWidget *centralWidget;
QScrollArea *scrollArea;
QWidget *scrollAreaWidgetContents;
QPushButton *pBut_up;
QPushButton *pBut_next;
QRadioButton *rBut_ans_a;
QRadioButton *rBut_ans_b;
QRadioButton *rBut_ans_c;
QRadioButton *rBut_ans_d;
QScrollArea *scrollArea_2;
QWidget *scrollAreaWidgetContents_2;
QScrollBar *verticalScrollBar;
QLabel *label_hint;
QLabel *label_time;
QMenuBar *menuBar;
QMenu *menu_file;
QMenu *menu_tool;
QMenu *menu_set;
QMenu *menu_help;
QStatusBar *statusBar;
void setupUi(QMainWindow *m_window)
{
if (m_window->objectName().isEmpty())
m_window->setObjectName(QString::fromUtf8("m_window"));
m_window->setEnabled(true);
m_window->resize(650, 420);
m_window->setMinimumSize(QSize(650, 420));
m_window->setMaximumSize(QSize(650, 420));
menu_start = new QAction(m_window);
menu_start->setObjectName(QString::fromUtf8("menu_start"));
menu_start->setAutoRepeat(false);
menu_exit = new QAction(m_window);
menu_exit->setObjectName(QString::fromUtf8("menu_exit"));
action_3 = new QAction(m_window);
action_3->setObjectName(QString::fromUtf8("action_3"));
action_5 = new QAction(m_window);
action_5->setObjectName(QString::fromUtf8("action_5"));
action_6 = new QAction(m_window);
action_6->setObjectName(QString::fromUtf8("action_6"));
menu_sysset = new QAction(m_window);
menu_sysset->setObjectName(QString::fromUtf8("menu_sysset"));
menu_queset = new QAction(m_window);
menu_queset->setObjectName(QString::fromUtf8("menu_queset"));
menu_login = new QAction(m_window);
menu_login->setObjectName(QString::fromUtf8("menu_login"));
menu_bbs = new QAction(m_window);
menu_bbs->setObjectName(QString::fromUtf8("menu_bbs"));
menu_learn = new QAction(m_window);
menu_learn->setObjectName(QString::fromUtf8("menu_learn"));
action_12 = new QAction(m_window);
action_12->setObjectName(QString::fromUtf8("action_12"));
action_14 = new QAction(m_window);
action_14->setObjectName(QString::fromUtf8("action_14"));
centralWidget = new QWidget(m_window);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
scrollArea = new QScrollArea(centralWidget);
scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
scrollArea->setGeometry(QRect(10, 40, 491, 321));
scrollArea->setWidgetResizable(true);
scrollAreaWidgetContents = new QWidget();
scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
scrollAreaWidgetContents->setGeometry(QRect(0, 0, 489, 319));
scrollArea->setWidget(scrollAreaWidgetContents);
pBut_up = new QPushButton(centralWidget);
pBut_up->setObjectName(QString::fromUtf8("pBut_up"));
pBut_up->setGeometry(QRect(520, 170, 75, 23));
pBut_next = new QPushButton(centralWidget);
pBut_next->setObjectName(QString::fromUtf8("pBut_next"));
pBut_next->setGeometry(QRect(520, 200, 75, 23));
rBut_ans_a = new QRadioButton(centralWidget);
rBut_ans_a->setObjectName(QString::fromUtf8("rBut_ans_a"));
rBut_ans_a->setGeometry(QRect(520, 60, 89, 16));
rBut_ans_b = new QRadioButton(centralWidget);
rBut_ans_b->setObjectName(QString::fromUtf8("rBut_ans_b"));
rBut_ans_b->setGeometry(QRect(520, 80, 89, 16));
rBut_ans_c = new QRadioButton(centralWidget);
rBut_ans_c->setObjectName(QString::fromUtf8("rBut_ans_c"));
rBut_ans_c->setGeometry(QRect(520, 100, 89, 16));
rBut_ans_d = new QRadioButton(centralWidget);
rBut_ans_d->setObjectName(QString::fromUtf8("rBut_ans_d"));
rBut_ans_d->setGeometry(QRect(520, 120, 89, 16));
scrollArea_2 = new QScrollArea(centralWidget);
scrollArea_2->setObjectName(QString::fromUtf8("scrollArea_2"));
scrollArea_2->setGeometry(QRect(10, 40, 491, 321));
scrollArea_2->setWidgetResizable(true);
scrollAreaWidgetContents_2 = new QWidget();
scrollAreaWidgetContents_2->setObjectName(QString::fromUtf8("scrollAreaWidgetContents_2"));
scrollAreaWidgetContents_2->setGeometry(QRect(0, 0, 489, 319));
verticalScrollBar = new QScrollBar(scrollAreaWidgetContents_2);
verticalScrollBar->setObjectName(QString::fromUtf8("verticalScrollBar"));
verticalScrollBar->setGeometry(QRect(471, 0, 20, 321));
verticalScrollBar->setOrientation(Qt::Vertical);
scrollArea_2->setWidget(scrollAreaWidgetContents_2);
label_hint = new QLabel(centralWidget);
label_hint->setObjectName(QString::fromUtf8("label_hint"));
label_hint->setGeometry(QRect(520, 30, 71, 31));
label_time = new QLabel(centralWidget);
label_time->setObjectName(QString::fromUtf8("label_time"));
label_time->setGeometry(QRect(520, 140, 81, 31));
m_window->setCentralWidget(centralWidget);
menuBar = new QMenuBar(m_window);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 650, 19));
menu_file = new QMenu(menuBar);
menu_file->setObjectName(QString::fromUtf8("menu_file"));
menu_tool = new QMenu(menuBar);
menu_tool->setObjectName(QString::fromUtf8("menu_tool"));
menu_set = new QMenu(menuBar);
menu_set->setObjectName(QString::fromUtf8("menu_set"));
menu_help = new QMenu(menuBar);
menu_help->setObjectName(QString::fromUtf8("menu_help"));
m_window->setMenuBar(menuBar);
statusBar = new QStatusBar(m_window);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
m_window->setStatusBar(statusBar);
menuBar->addAction(menu_file->menuAction());
menuBar->addAction(menu_tool->menuAction());
menuBar->addAction(menu_set->menuAction());
menuBar->addAction(menu_help->menuAction());
menu_file->addAction(menu_start);
menu_file->addAction(menu_exit);
menu_tool->addAction(menu_login);
menu_tool->addAction(menu_bbs);
menu_tool->addAction(menu_learn);
menu_tool->addSeparator();
menu_tool->addAction(action_12);
menu_tool->addAction(action_14);
menu_set->addAction(menu_sysset);
menu_set->addAction(menu_queset);
menu_help->addAction(action_3);
menu_help->addAction(action_5);
menu_help->addAction(action_6);
retranslateUi(m_window);
QMetaObject::connectSlotsByName(m_window);
} // setupUi
………………………………………………………………………………………………
namespace Ui {
class m_window: public Ui_m_window {};
} // namespace Ui
QT_END_NAMESPACE
#endif // GKXT2UW4872_H
[解决办法]
建议将ui声明成指针:
UI::m_window *ui;
构造函数相应增加初始化项:
Widget:: Widget(QWidget *parent)
: QWidget(parent),ui(new Ui::m_window)//不要忘记ui的初始化
{
...
}