PDA

View Full Version : SIGSEGV during startup processing SLOT



deanz1
24th January 2011, 19:50
I'm getting SIGSEGV during startup processing. I never reach the first line of my main. I have isolated this to an area of qobject.cpp near line 2537



if (!check_method_code(membcode, receiver, method, "connect"))
return false;
const char *method_arg = method;
++method; // skip code

const QMetaObject *rmeta = receiver->metaObject();
int method_index = -1;

The failure happens on the line containing "*remeta =" and I'm unable to trace into function metaObject. At the time, the metacode is processing my slot "catchLtiStart.

Here is code from "moc_opolib.cpp" re catchLtiStart and others:


int Opolib::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
switch (_id) {
case 0: lasLogin((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 1: lasSetParameters((*reinterpret_cast< const char*(*)>(_a[1]))); br
case 2: lasSend((*reinterpret_cast< const char*(*)>(_a[1]))); break;
case 3: lasSend((*reinterpret_cast< const char*(*)>(_a[1])),(*reinterpret
case 4: lasSend((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 5: lasLogout(); break;
case 6: motLogin((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 7: motSetParameters((*reinterpret_cast< const char*(*)>(_a[1]))); br
case 8: motSend((*reinterpret_cast< const char*(*)>(_a[1]))); break;
case 9: motSend((*reinterpret_cast< const char*(*)>(_a[1])),(*reinterpret
case 10: motSend((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 11: motLogout(); break;
case 12: lasError((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 13: motError((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 14: catchLtiStart(); break;
case 15: catchMtiStart(); break;
case 16: catchLasConnected(); break;
case 17: catchLasError((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 18: catchLasNewMessage((*reinterpret_cast< QByteArray(*)>(_a[1])));
case 19: catchLasTimedOut(); break;
case 20: catchLthFinished(); break;
case 21: catchMotConnected(); break;
case 22: catchMotError((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 23: catchMotNewMessage((*reinterpret_cast< QByteArray(*)>(_a[1])));
case 24: catchMotTimedOut(); break;
case 25: catchMthFinished(); break;
default: ;
}
_id -= 26;
}
return _id;
}

And catchLtiStart is the first SLOT listed (I name SLOTs as catch*).

SLOT catchLtiStart is not much:



public slots:
void catchLtiStart() {lti.start(TIMEOUT);} //start laser SerialClient breakout timer


I'm assuming this is memory corruption or, more likely, stack corruption but am at a loss as to where to look.

Any hints?

Added after 9 minutes:

Oops, sorry about the code markup.

Version info: Qt Creator 2.0.0 based on Qt 4.7.0 (32 bit) built Jun 21 2010 at 01:56:06 using MinGW compiler g++ 4.4.0 on Windows 7.

Lykurg
24th January 2011, 21:03
Is this specific to only one project, or are you unable to compile and start any Qt program at your computer?

deanz1
24th January 2011, 21:52
It's specific to this project; I have made a TCP/IP server previously using Qt and had no problems of this sort.

Added after 9 minutes:

Some further information:

I have a class "Laser" and a main class "Opolib". Opolib has a Laser member. The problem is arising during construction of member class "Laser. Here is the constructor:



Laser::Laser() : QObject(0), per(0)
{
connect(this, SIGNAL(ltiStart()), ol, SLOT(catchLtiStart())
, Qt::QueuedConnection);
thr = new QThreadExec;
moveToThread(thr);
thr->start();
}


And here is the definition of class "Laser":


class Laser : public QObject {
Q_OBJECT

LasCmd cmd; //command to send or last sent
int delay; //delay argument to Q-Switch
Opolib *ol; //cross-reference
int per; //percent of full power
QByteArray qarr; //general purpose byte array
QString qstr; //general purpose string
QThreadExec *thr; //thread event loop for Laser object

public:
Distrib dist; //persistent data for distributed processing
double delayGain; //Q-Switch delay slope
double minDelay; //Q-Switch delay for minimum laser power

//ctors
Laser();

//accessors
void setOpolib(Opolib *Ol) {ol = Ol;}

//methods
void lasCommand(
QByteArray &msg);
int percent() {return per;}

signals:
void lasError(QString);
void lasFinis();
void lasLogout();
void lasSend(const char*);
void lasSend(const char*, int);
void lasSend(QString);
void ltiStart();

public slots:
void commandLas(LasCmd Cmd)
{
QByteArray qa;
qa[0] = '\0';
memset(&dist, '\0', sizeof(dist));
cmd = Cmd;
lasCommand(qa);
}
void setLasPower(int percent)
{
per = qBound(0, percent, 100);
delay = int(minDelay + delayGain*per);
commandLas(LasDelay);
}
};


Added after 6 minutes:

Yee Hah! The Aha moment dawns.

I think I see the problem. At the time that the Laser object is being constructed, the cross-reference pointer has not yet been set. Anybody concur?

Lykurg
24th January 2011, 21:54
Well it seems to me that in the c-tor ol is uninitialized! Try to do the connection in setOpolib().

EDIT: Yes...

deanz1
24th January 2011, 22:33
That was the problem.


Thanks to all for the help and, in the spirit of Homer, Doh!