• 3575阅读
  • 0回复

SIGNAL SIGSEGV 错误请教( 凡是带Q_OBJECT就出错 ) [复制链接]

上一主题 下一主题
离线kmine
 
只看楼主 倒序阅读 楼主  发表于: 2008-08-05
— 本帖被 XChinux 执行加亮操作(2008-08-06) —
我做了一个QThread类线程的测试,有段错误出现,整个程序源码如下:
//main.cpp
#include <qapplication.h>
#include "test.h"

int main( int argc, char ** argv )
{
    QApplication a( argc, argv );
    Test w;
    w.show();
    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    return a.exec();
}

//threadTest.h
#ifndef THREADTEST_H
#define THREADTEST_H

#include <qthread.h>

class MyThread : public QThread

    protected :
    virtual void run();
};

#endif

//threadTest.cpp
#include "threadTest.h"
#include <stdio.h>

void MyThread::run()
{
    for(int i=0;i <100;i++)
printf("new value i is:%d",i);
}

//test.ui.h
#include "threadTest.h"

MyThread myThread;

void Test::newSlot()
{
    myThread.start();
}

//test.h
#ifndef TEST_H
#define TEST_H

#include <qvariant.h>
#include <qwidget.h>

class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QLineEdit;
class QPushButton;
class QTextEdit;

class Test : public QWidget
{
    Q_OBJECT

public:
    Test( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
    ~Test();

    QTextEdit* textEdit1;
    QLineEdit* lineEdit1;
    QPushButton* pushButton2;
    QPushButton* pushButton1;

public slots:
    virtual void newSlot();

protected:

protected slots:
    virtual void languageChange();
};

#endif // TEST_H


//test.cpp

#include "test.h"

#include <qvariant.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qtextedit.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>

#include "../test.ui.h"
/*
*  Constructs a Test as a child of 'parent', with the
*  name 'name' and widget flags set to 'f'.
*/
Test::Test( QWidget* parent, const char* name, WFlags fl )
    : QWidget( parent, name, fl )
{
    if ( !name )
setName( "Test" );

    textEdit1 = new QTextEdit( this, "textEdit1" );
    textEdit1->setGeometry( QRect( 10, 60, 570, 291 ) );

    lineEdit1 = new QLineEdit( this, "lineEdit1" );
    lineEdit1->setGeometry( QRect( 10, 360, 571, 31 ) );

    pushButton2 = new QPushButton( this, "pushButton2" );
    pushButton2->setGeometry( QRect( 380, 400, 201, 41 ) );

    pushButton1 = new QPushButton( this, "pushButton1" );
    pushButton1->setGeometry( QRect( 10, 10, 261, 41 ) );
    languageChange();
    resize( QSize(600, 480).expandedTo(minimumSizeHint()) );

    // signals and slots connections
    connect( pushButton1, SIGNAL( released() ), this, SLOT( newSlot() ) );
}

/*
*  Destroys the object and frees any allocated resources
*/
Test::~Test()
{
    // no need to delete child widgets, Qt does it all for us
}

/*
*  Sets the strings of the subwidgets using the current
*  language.
*/
void Test::languageChange()
{
    setCaption( tr( "Thread Test" ) );
    pushButton2->setText( tr( "pushButton2" ) );
    pushButton1->setText( tr( "pushButton1" ) );
}
当程序运行时,按下pushButton1开始运行线程,然后关闭程序时,就会弹出段错误,我用GDB来调试:
Program received signal SIGSEGV,Segmentation fault.
[Switching to Thread 1084948864(LWP 2084)]
0x404f2002 in QMutexPool::get(void *)()from/usr/lib/qt-3.1/lib/libqt-mt.so.3
我的程序里就没有用到QMutexPool,到底是哪里错误了,请高手救命呀

主要是metaobject引用了无效地址,这是为什么,只要有用Q_OBJECT宏定义,moc也正常,编译无措,但是运行就出类似上面的错。
快速回复
限100 字节
 
上一个 下一个