yektaayduk
16th January 2008, 17:23
Hi
Inside a child widget (=checklists) I have created a QTable . I want to access QTable Items of this table by calling a child widget function ,Report_Test1() .
When I call Report_Test1() from the main Widget(=GLObjectWindow ) the line related to QtableItem access cause a segmentation fault.
The simplified source code for main.cpp ,globjwin.cpp.h,selftest.cpp.h are below.
Can you contribute to solution,thank you.
int main( int argc, char **argv )
{
GLObjectWindow w;
a.setMainWidget( &w );
}
//--------globjwin.h--------------------
class GLObjectWindow : public QWidget
{
Q_OBJECT
public:
GLObjectWindow( QWidget *parent=0, const char *name=0 );
public:
CheckLists *checklists;
}
//----------globjwin.h------------------
//----------globjwin.cpp----------------
GLObjectWindow::GLObjectWindow( QWidget* parent, const char* name )
: QWidget( parent, name )
{
}
void GLObjectWindow::CreateSelfTestDialog( )
{
printf("CreateSelfTestDialog executed\n");
static CheckLists *checklists=new CheckLists;
checklists->show();
checklists-> raise();
checklists->setWindowState(Qt::WindowActive);
}
void GLObjectWindow::GetTestReports( )
{
checklists->Report_Test1();//++++++++++++++++++++++++++++++++--calling from here cause segfault
checklists->Report_Test2();//++++++++++++++++++++++++++++++++--calling from here cause segfault
}
//----------globjwin.cpp----------------
//----selftest.h------------------------
class CheckLists : public QWidget
{
Q_OBJECT
public:
CheckLists( QWidget *parent = 0, const char *name = 0 );
public:
void Report_Test1();
void Report_Test2();
public:
QTable *table_selftest;
QHeader *header;
};
//----selftest.h------------------------
//------------selftest.cpp--------------
CheckLists::CheckLists( QWidget *parent, const char *name )
: QWidget( parent, name )
{
QHBoxLayout *lay = new QHBoxLayout( this );
lay->setMargin( 5 );
// create a widget which layouts its childs in a column
QVBoxLayout *vbox1 = new QVBoxLayout( lay );
vbox1->setMargin( 5 );
// First child: a Label
vbox1->addWidget( new QLabel( "Check some items!", this ) );
table_selftest = new QTable( 5,2,this );
vbox1->addWidget( table_selftest );
table_selftest->horizontalHeader()->setLabel( 0, trUtf8(" Test") );
table_selftest->horizontalHeader()->setLabel( 1, trUtf8(" Result") );
QTableItem *test_1 = new QTableItem( table_selftest, QTableItem::Never, trUtf8( "Test 1") );
table_selftest->setItem( 0, 0, test_1 );
QTableItem *test_2 = new QTableItem( table_selftest, QTableItem::Never, trUtf8( "Test 2 ") );
table_selftest->setItem( 1, 0, test_2 );
QTableItem *test_3 = new QTableItem( table_selftest, QTableItem::Never, trUtf8( "Test 3") );
table_selftest->setItem( 2, 0, test_3 );
table_selftest->setText( 0, 1, "-" );
table_selftest->setText( 1, 1, "-" );
table_selftest->setText( 2, 1, "-" );
Report_Test1(); //-++++++++++++++++++++++-calling from here doesnt cause segfault
Report_Test2();//--+++++++++++++++++++++++calling from here doesnt cause segfault
}
//------------------------------------------------------------------------------------
void CheckLists::Report_Test1()
{
this->table_selftest->setText( 1, 1, "OK" );
}
//------------------------------------------------------------------------------------
void CheckLists::Report_Test2()
{
this->table_selftest->setText( 2, 1, "OK" );
}
//------------selftest.cpp--------------
Yekta Ayduk
Inside a child widget (=checklists) I have created a QTable . I want to access QTable Items of this table by calling a child widget function ,Report_Test1() .
When I call Report_Test1() from the main Widget(=GLObjectWindow ) the line related to QtableItem access cause a segmentation fault.
The simplified source code for main.cpp ,globjwin.cpp.h,selftest.cpp.h are below.
Can you contribute to solution,thank you.
int main( int argc, char **argv )
{
GLObjectWindow w;
a.setMainWidget( &w );
}
//--------globjwin.h--------------------
class GLObjectWindow : public QWidget
{
Q_OBJECT
public:
GLObjectWindow( QWidget *parent=0, const char *name=0 );
public:
CheckLists *checklists;
}
//----------globjwin.h------------------
//----------globjwin.cpp----------------
GLObjectWindow::GLObjectWindow( QWidget* parent, const char* name )
: QWidget( parent, name )
{
}
void GLObjectWindow::CreateSelfTestDialog( )
{
printf("CreateSelfTestDialog executed\n");
static CheckLists *checklists=new CheckLists;
checklists->show();
checklists-> raise();
checklists->setWindowState(Qt::WindowActive);
}
void GLObjectWindow::GetTestReports( )
{
checklists->Report_Test1();//++++++++++++++++++++++++++++++++--calling from here cause segfault
checklists->Report_Test2();//++++++++++++++++++++++++++++++++--calling from here cause segfault
}
//----------globjwin.cpp----------------
//----selftest.h------------------------
class CheckLists : public QWidget
{
Q_OBJECT
public:
CheckLists( QWidget *parent = 0, const char *name = 0 );
public:
void Report_Test1();
void Report_Test2();
public:
QTable *table_selftest;
QHeader *header;
};
//----selftest.h------------------------
//------------selftest.cpp--------------
CheckLists::CheckLists( QWidget *parent, const char *name )
: QWidget( parent, name )
{
QHBoxLayout *lay = new QHBoxLayout( this );
lay->setMargin( 5 );
// create a widget which layouts its childs in a column
QVBoxLayout *vbox1 = new QVBoxLayout( lay );
vbox1->setMargin( 5 );
// First child: a Label
vbox1->addWidget( new QLabel( "Check some items!", this ) );
table_selftest = new QTable( 5,2,this );
vbox1->addWidget( table_selftest );
table_selftest->horizontalHeader()->setLabel( 0, trUtf8(" Test") );
table_selftest->horizontalHeader()->setLabel( 1, trUtf8(" Result") );
QTableItem *test_1 = new QTableItem( table_selftest, QTableItem::Never, trUtf8( "Test 1") );
table_selftest->setItem( 0, 0, test_1 );
QTableItem *test_2 = new QTableItem( table_selftest, QTableItem::Never, trUtf8( "Test 2 ") );
table_selftest->setItem( 1, 0, test_2 );
QTableItem *test_3 = new QTableItem( table_selftest, QTableItem::Never, trUtf8( "Test 3") );
table_selftest->setItem( 2, 0, test_3 );
table_selftest->setText( 0, 1, "-" );
table_selftest->setText( 1, 1, "-" );
table_selftest->setText( 2, 1, "-" );
Report_Test1(); //-++++++++++++++++++++++-calling from here doesnt cause segfault
Report_Test2();//--+++++++++++++++++++++++calling from here doesnt cause segfault
}
//------------------------------------------------------------------------------------
void CheckLists::Report_Test1()
{
this->table_selftest->setText( 1, 1, "OK" );
}
//------------------------------------------------------------------------------------
void CheckLists::Report_Test2()
{
this->table_selftest->setText( 2, 1, "OK" );
}
//------------selftest.cpp--------------
Yekta Ayduk