• 8646阅读
  • 7回复

[提问]Qt (ubuntu )运行时错误:段错误(核心已转储) [复制链接]

上一主题 下一主题
离线trojanhorse
 
只看楼主 倒序阅读 楼主  发表于: 2012-12-05
我是个Qt 初学者,我根据《C++ qt GUI 编程》中的那个shape changing dialog自己手写了代码来实习(书上是用Qt designer做的),构建没有错误,但是在运行时出现错误: 段错误(核心已转储)。我用的是ubuntu 12.04 和qt 4.8,代码如下:
//sortdialog.h--------------------------------------------------------------------------------------------------------------------------------------------------------------------

#ifndef SORTDIALOG_H
#define SORTDIALOG_H

#include<QtGui>
class sortDialog:public QDialog
{

public:
sortDialog(QWidget *parent=0);
void setComboRange(QChar first,QChar last);
private:
QGroupBox *group;
QGroupBox *group_2;
QGroupBox *group_3;
QComboBox *combo_11,*combo_12,*combo_21,*combo_22,*combo_31,*combo_32;
QLabel *label_11,*label_12,*label_21,*label_22,*label_31,*label_32;
QPushButton *okButton,*cancelButton,*moreButton;
QHBoxLayout *hLayout_1;
QVBoxLayout *vLayout_1;
QHBoxLayout *hLayout_2;
QVBoxLayout *vLayout_2;
QHBoxLayout *hLayout_3;
QVBoxLayout *vLayout_3;

QVBoxLayout *leftUpLayout;
QHBoxLayout *upLayout;

QVBoxLayout *rightLayout;

QVBoxLayout *mainLayout;

};

void sortDialog::setComboRange(QChar first,QChar last)
{
combo_11->clear();
combo_12->clear();
combo_21->clear();
combo_22->clear();
combo_31->clear();
combo_32->clear();
combo_11->addItem("None");
combo_12->addItem("Ascending");
combo_12->addItem("Descending");
combo_21->addItem("None");
combo_22->addItem("Ascending");
combo_22->addItem("Descending");
combo_31->addItem("None");
combo_32->addItem("Ascending");
combo_32->addItem("Descending");
QChar ch=first;
while(ch<=last)
{
combo_11->addItem(QString(ch));
combo_21->addItem(QString(ch));
combo_31->addItem(QString(ch));
ch=ch.unicode()+1;
}

}



sortDialog::sortDialog(QWidget *parent):QDialog(parent)
{
group->setTitle(tr("&Primary key"));
group_2->setTitle(tr("&Secondary key"));
group_3->setTitle(tr("&Tertiary key"));
setComboRange('A','Z');
label_11=new QLabel(tr("Column:"));
label_12=new QLabel(tr("Order:"));
label_21=new QLabel(tr("Column:"));
label_22=new QLabel(tr("Order:"));
label_31=new QLabel(tr("Column:"));
label_32=new QLabel(tr("Order:"));
okButton=new QPushButton(tr("&OK"));
cancelButton=new QPushButton(tr("&Cancel"));
moreButton=new QPushButton(tr("&More"));

hLayout_1=new QHBoxLayout;
hLayout_1->addWidget(combo_11);
hLayout_1->addStretch();
vLayout_1=new QVBoxLayout;
vLayout_1->addLayout(hLayout_1);
vLayout_1->addWidget(combo_12);
group->setLayout(vLayout_1);

hLayout_2=new QHBoxLayout;
hLayout_2->addWidget(combo_21);
hLayout_2->addStretch();
vLayout_2=new QVBoxLayout;
vLayout_2->addLayout(hLayout_2);
vLayout_2->addWidget(combo_22);
group_2->setLayout(vLayout_2);

hLayout_3=new QHBoxLayout;
hLayout_3->addWidget(combo_31);
hLayout_3->addStretch();
vLayout_3=new QVBoxLayout;
vLayout_3->addLayout(hLayout_3);
vLayout_3->addWidget(combo_32);
group_3->setLayout(vLayout_3);

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

leftUpLayout=new QVBoxLayout;
leftUpLayout->addWidget(group);
leftUpLayout->addStretch();

upLayout=new QHBoxLayout;
upLayout->addLayout(leftUpLayout);
upLayout->addLayout(rightLayout);


mainLayout=new QVBoxLayout;
mainLayout->addLayout(upLayout);
mainLayout->addWidget(group_2);
mainLayout->addWidget(group_3);

setLayout(mainLayout);


QObject::connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
QObject::connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
QObject::connect(moreButton,SIGNAL(toggled(bool)),group_2,SLOT(setVisible(bool)));
QObject::connect(moreButton,SIGNAL(toggled(bool)),group_3,SLOT(setVisible(bool)));

}

#endif


//main.cpp--------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include<QApplication>
#include"sortdialog.h"
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
sortDialog s;
s.show();
return app.exec();
}

求高手指教!!!不胜感激。














离线roywillow

只看该作者 1楼 发表于: 2012-12-05
我仿佛没看到那些combobox的实例化?然后后面就使用这些指针了?
另外那些已经实例化的组件都没parent啊
专业维修核潜艇,回收二手航母、二手航天飞机,大修核反应堆,拆洗导弹发动机更换机油,无人侦察机手动挡改自动,航天飞机保养换三滤,飞碟外太空年检 ,各型号导弹加装迎宾踏板,高空作业擦洗卫星表面除尘、打蜡及抛光,东风全系列巡航导弹。并提供原子对撞机。量大从优,有正规发票。
离线trojanhorse
只看该作者 2楼 发表于: 2012-12-06
回 1楼(roywillow) 的帖子
真是你所的,我用了野指针。可是修改后程序能运行,但是点moreButton 的时候下面两个goupbox没有隐藏起来。moreButton好像失去效果了。
离线roywillow

只看该作者 3楼 发表于: 2012-12-06
回 2楼(trojanhorse) 的帖子
看看文档再确认一下那个信号的意义?
另外确认一下button的Checkable属性?
专业维修核潜艇,回收二手航母、二手航天飞机,大修核反应堆,拆洗导弹发动机更换机油,无人侦察机手动挡改自动,航天飞机保养换三滤,飞碟外太空年检 ,各型号导弹加装迎宾踏板,高空作业擦洗卫星表面除尘、打蜡及抛光,东风全系列巡航导弹。并提供原子对撞机。量大从优,有正规发票。
离线trojanhorse
只看该作者 4楼 发表于: 2012-12-06
真是checkable 属性没有设置,大牛,让我膜拜一下!
离线roywillow

只看该作者 5楼 发表于: 2012-12-06
回 4楼(trojanhorse) 的帖子
另外给那些孩子都找个爹妈吧……
专业维修核潜艇,回收二手航母、二手航天飞机,大修核反应堆,拆洗导弹发动机更换机油,无人侦察机手动挡改自动,航天飞机保养换三滤,飞碟外太空年检 ,各型号导弹加装迎宾踏板,高空作业擦洗卫星表面除尘、打蜡及抛光,东风全系列巡航导弹。并提供原子对撞机。量大从优,有正规发票。
离线trojanhorse
只看该作者 6楼 发表于: 2012-12-06
回 5楼(roywillow) 的帖子
parent指针的作用到底是什么?
离线roywillow

只看该作者 7楼 发表于: 2012-12-06
回 6楼(trojanhorse) 的帖子
parent析构的时候自动析构其children,因为没看到你手动delete那些成员
专业维修核潜艇,回收二手航母、二手航天飞机,大修核反应堆,拆洗导弹发动机更换机油,无人侦察机手动挡改自动,航天飞机保养换三滤,飞碟外太空年检 ,各型号导弹加装迎宾踏板,高空作业擦洗卫星表面除尘、打蜡及抛光,东风全系列巡航导弹。并提供原子对撞机。量大从优,有正规发票。
快速回复
限100 字节
 
上一个 下一个