点击按键后为什么没反应???

ajew_de 2010-03-05 03:49:57
我是新手,在学校做一个课题,要给C++的LinkedList做一个界面。先看源代码:

#ifndef CREATENODEINFORMATION_H_
#define CREATENODEINFORMATION_H_
#include <QDialog>
#include "node.h"

class CreateNodeInformation: public QDialog {
public:
CreateNodeInformation(Node* newNode, QWidget* parent=0);
virtual ~CreateNodeInformation();

private slots:
void confirm();

private:
QLabel *label;
QLineEdit *lineEdit;
QPushButton *okButton;
QPushButton *cancelButton;
Node* node;
};

#endif /* CREATENODEINFORMATION_H_ */






#include <QtGUI>
#include "createnodeinformation.h"

CreateNodeInformation::CreateNodeInformation(Node* newNode, QWidget* parent) {
node = newNode;

label = new QLabel("Please input your text");
lineEdit = new QLineEdit;
node->setText("new Node");
lineEdit->setText(node->text());
okButton = new QPushButton("OK", this);
cancelButton = new QPushButton("CANCEL", this);

connect(okButton, SIGNAL(clicked()), this, SLOT(confirm()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));

QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(label);
topLeftLayout->addWidget(lineEdit);

QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);

QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(okButton);
rightLayout->addWidget(cancelButton);
rightLayout->addStretch();

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);

setWindowTitle(("Create New Node"));
setFixedHeight(sizeHint().height());
}

CreateNodeInformation::~CreateNodeInformation() {
node = NULL;
}

void CreateNodeInformation::confirm(){
node->setText(lineEdit->text());
QDialog::accept();
}


Class Node我就不贴了,我这个CreateNodeInformation应该让使用者为新建的Node输入要显示在Node里边的字符串,初始只是“new Node”。测试时显示节点是没有问题的,可是点击OK键为什么没有任何反应(Cancel键正常)?

拜谢!!!
...全文
218 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jerry_Lee01 2010-03-12
  • 打赏
  • 举报
回复
跟踪调试下
czg_1111111111 2010-03-11
  • 打赏
  • 举报
回复
头文件中修改
class CreateNodeInformation: public QDialog {
Q_OBJECT

......
}

并用moc程序预编译头文件,然后把生成的文件#include进你的工程
tingsking18 2010-03-08
  • 打赏
  • 举报
回复
用了slots,但是却没有Q_OBJECT。
不知道如何编译过的

qter_wd007 2010-03-06
  • 打赏
  • 举报
回复
设置断点,调试一下看看
skly22222 2010-03-06
  • 打赏
  • 举报
回复
初始化的时候
node->setText("new Node");
lineEdit->setText(node->text());
lineEdit里面就是"new Node";
confirm()里面
node->setText(lineEdit->text());

tzcherish 2010-03-06
  • 打赏
  • 举报
回复
同意2楼。。。
单步跟,找出问题所在
willow_z 2010-03-06
  • 打赏
  • 举报
回复
我也碰到过类似的问题。书上就是这样写的,可是它的程序能用,我的就不能!郁闷!
MicroSky2813 2010-03-05
  • 打赏
  • 举报
回复
这么长的贴子,等上完课再来看
dyw 2010-03-05
  • 打赏
  • 举报
回复
没看出问题所在,建议设断点跟踪一下。

16,212

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧