qt make 没error,run的时候按下push button会报abort
刚学qt,写的一个dialog程序,主窗口按setting键弹出dialog窗口,在dialog窗口中设置数值,获取数值,按enter确定,按cancel取消,现在遇到的问题是按下enter会abort,麻烦各位高手帮忙,谢谢!main_form.h如下:
#if !defined (__MAIN_FORM_H__)
# define __MAIN_FORM_H__
#include "main_form_base.h"
#include <qevent.h>
#include <qdialog.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <qwidget.h>
#include <qlabel.h>
class TMainForm: public TMainFormBase {
Q_OBJECT
public:
TMainForm(QWidget * parent = 0, const char * name = 0, WFlags f = WType_TopLevel) : TMainFormBase(parent,name,f) {}
virtual ~TMainForm() {}
public slots:
void setting_slot();
};
class setting_dialog : public QDialog
{
Q_OBJECT
private slots:
void enterClicked();
void cancelClicked();
public:
QLineEdit *edit1;
QLineEdit *edit2;
QLineEdit *edit3;
QLineEdit *edit4;
QLineEdit *edit5;
QLabel *labele;
QLabel *label1;
QLabel *label2;
QLabel *label3;
QLabel *label4;
QLabel *label5;
QLabel *label6;
QLabel *myip;
};
#endif
main_form.cpp如下:
#include "main_form.h"
#include <qlineedit.h>
#include <qlabel.h>
#include <qdialog.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <stdio.h>
struct IpAddr{
unsigned char a;
unsigned char b;
unsigned char c;
unsigned char d;
}ip1;
float db_thd;
void setting_dialog::enterClicked()
{
if (edit1->text().isEmpty() ) {
return ;
}
}
void setting_dialog::cancelClicked()
{
printf("ok");
close();
}
void TMainForm::setting_slot()
{
setting_dialog * dialog = new setting_dialog();
dialog->setCaption("Setting Window");
dialog->setMinimumSize(480,272);
QGridLayout *grid = new QGridLayout(dialog, 3, 2, 2, 2);
QPushButton *btn = new QPushButton("Cancel",dialog);
btn->setGeometry(50, 20, 100, 40);
connect(btn, SIGNAL(clicked()), dialog, SLOT(accept()));
grid->addWidget( btn, 2, 5 );
QPushButton *etr = new QPushButton("Enter",dialog);
etr->setGeometry(50, 20, 100, 40);
connect(etr, SIGNAL(clicked()), dialog, SLOT(enterClicked()));
grid->addWidget( etr, 2, 3 );
QLabel *label1 = new QLabel( "IP Addr:", dialog);
grid->addWidget( label1, 0, 0 );
QLabel *label2 = new QLabel( ".", dialog);
grid->addWidget( label2, 0, 2 );
QLabel *label3 = new QLabel( ".", dialog);
grid->addWidget( label3, 0, 4 );
QLabel *label4 = new QLabel( ".", dialog);
grid->addWidget( label4, 0, 6 );
QLabel *labele = new QLabel( " ", dialog);
grid->addWidget( labele, 0, 8 );
QLineEdit *edit1 = new QLineEdit(dialog);
grid->addWidget( edit1, 0, 1 );
QLineEdit *edit2 = new QLineEdit(dialog);
grid->addWidget( edit2, 0, 3 );
QLineEdit *edit3 = new QLineEdit(dialog);
grid->addWidget( edit3, 0, 5 );
QLineEdit *edit4 = new QLineEdit(dialog);
grid->addWidget( edit4, 0, 7 );
QLabel *label5 = new QLabel( "dB threshold:", dialog);
grid->addWidget( label5, 1, 0 );
QLineEdit *edit5 = new QLineEdit(dialog);
grid->addWidget( edit5, 1, 1 );
QLabel *label6 = new QLabel( "dB", dialog);
grid->addWidget( label6, 1, 2 );
// QLabel *myip = new QLabel( " ", dialog);
dialog->show();
}
--------------------编程问答-------------------- 你调试运行一下,出错后看指向哪行代码 --------------------编程问答-------------------- 你把你的setdialog好好封装一下吧,所有的控件声明写到.h文件里去,创建和布局写到.cpp里,在槽函数中才创建dialog是不好的习惯。
建议在主程序启动时就创建setdialog,但不显示出来,当点击设置按钮时,setdialog->show()。
补充:移动开发 , Qt