[SOLVED] My Qt class and QTableWidget
-
wrote on 12 Nov 2011, 17:15 last edited by
I am writing my "QTemplate" class which have to modify my QTableWidget from UI.
mainwindow.cpp (in constructor)
@term = new QTemplate(*ui->templates);@qtemplate.h
@class QTemplate : public QObject
{
Q_OBJECT
public:
explicit QTemplate(QTableWidget &wgt, QObject *parent = 0);@qtemplate.cpp
@QTemplate::QTemplate(QTableWidget &wgt, QObject *parent) :
QObject(parent)
{
table = &wgt;
timer = new QTimer(this);
connect(this,SIGNAL(started()),this,SLOT(placeCells()));
connect(this,SIGNAL(painted()),this,SLOT(wait()));
}@Program crashes on constructor of function start()
-
wrote on 12 Nov 2011, 17:16 last edited by
There are no errors and warnings while compiling.
-
wrote on 12 Nov 2011, 17:29 last edited by
So... what does your debugger tell you?
-
wrote on 12 Nov 2011, 17:31 last edited by
looks ok. what does the debugger say? UPD. ups)
-
wrote on 12 Nov 2011, 17:36 last edited by
Signal name :
SIGSEGV
Signal meaning :
Segmentation faultOn a first call to QTableWidget (function clearContents())
-
wrote on 12 Nov 2011, 17:38 last edited by
so where's the code for that? I don't see any calls in constructor
-
wrote on 12 Nov 2011, 17:38 last edited by
Of what type is member table?
Where exactly does the crash happen?PS:
While there is no official registry for class name prefixes, it is common sense and highly recommended to not use Q for your own classes, as this is the prefix used by Qt itself. So, to not clash with future Qt versions, you should rename QTemplate to something different. -
wrote on 12 Nov 2011, 17:42 last edited by
[quote author="Kxyu" date="1321119486"]so where's the code for that? I don't see any calls in constructor[/quote]
It in start() function:
@void QTemplate::start(int m, int c) {
table->clear();
msec = m;
cells = c;
emit started();
}@[quote author="Volker" date="1321119539"]Of what type is member table?
Where exactly does the crash happen?PS:
While there is no official registry for class name prefixes, it is common sense and highly recommended to not use Q for your own classes, as this is the prefix used by Qt itself. So, to not clash with future Qt versions, you should rename QTemplate to something different.[/quote]Declaration of 'table':
@QTableWidget* table;@Error on first call to 'table'
-
wrote on 12 Nov 2011, 17:45 last edited by
Check that table is not NULL.
-
wrote on 12 Nov 2011, 17:48 last edited by
Ok. Now I don't see where start() is called. Looks like table points to nowhere.
-
wrote on 12 Nov 2011, 17:50 last edited by
[quote author="Volker" date="1321119951"]Check that table is not NULL.[/quote]
In constructor:
@table = &wgt;@
It can't be NULL.[quote author="Kxyu" date="1321120089"]Ok. Now I don't see where start() is called. Looks like table points to nowhere. [/quote]
In MainWindow:
@void MainWindow::startTemplate()
{
term->start(1200,3);
}@ -
wrote on 12 Nov 2011, 17:58 last edited by
i guess we need only one piece of that puzzle - the code of MainWindow constructor
-
wrote on 12 Nov 2011, 17:59 last edited by
[quote author="Kxyu" date="1321120692"]i guess we need only one piece of that puzzle - the code of MainWindow constructor[/quote]
Please:
@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
classicTimer = new QTimer(this);
term = new QTemplate(*ui->templates);
setWindowIcon(QIcon(":/favicon.png"));
setGeometry(150,100,960,670);
}@@#ifdef ru_RU
"Так что там с пазлом?"
#endif@ -
wrote on 12 Nov 2011, 18:08 last edited by
Ok, we're almost there) What we need to see is the relation between
@term = new QTemplate(*ui->templates);@and
@table->clear();@
so I 'll ask you to show the place where startTemplate is called, the place where that place is called and so on. So you'd better show us the whole code)
@#ifdef ru_RU
"Разберемся)"
#endif@ -
wrote on 12 Nov 2011, 18:14 last edited by
[quote author="Kxyu" date="1321121317"]Ok, we're almost there) What we need to see is the relation between
@term = new QTemplate(*ui->templates);@and
@table->clear();@
so I 'll ask you to show the place where startTemplate is called, the place where that place is called and so on. So you'd better show us the whole code)
@#ifdef ru_RU
"Разберемся)"
#endif@
[/quote]Can you chat outside DevNet?
All my contacts in profile.
-
wrote on 12 Nov 2011, 18:24 last edited by
If you want your questions to be answered in russian you can post them "here":http://developer.qt.nokia.com/forums/viewforum/29/
-
wrote on 12 Nov 2011, 18:27 last edited by
OK. I can give you whole my MainWindow code.
@#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
classicTimer = new QTimer(this);
term = new QTemplate(*ui->templates);
setWindowIcon(QIcon(":/favicon.png"));
setGeometry(150,100,960,670);
// *** Connects of TEMPLATE *** //
connect(ui->templateStart,SIGNAL(clicked()),this,SLOT(startTemplate()));
// *** END connects of TEMPLATE *** //
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}void MainWindow::startTemplate()
{
term->start(1200,3);
}@ -
wrote on 13 Nov 2011, 00:35 last edited by
The code does not look fishy from what we know. Did you try to compile the program in debug mode and run it through the debugger already? This way you know where it bails out.
-
wrote on 13 Nov 2011, 19:52 last edited by
Thanks everybody. I found error and fixed it, so I am closing topic.
-
wrote on 13 Nov 2011, 20:29 last edited by
So, could you please post your solution? It could help others with similar issues.
BTW: topics are closed by moderators, not by users ;-) But you are very much invited to mark your topic as [Solved] by clicking the small edit link next to the first posting in the topic. That allows you to edit the title of the topic.
10/20