PDA

View Full Version : Problem with connect()



mrnor3
23rd July 2008, 11:38
Hallo everybody.

I have a problem with using connect between two different objects and methods, here
is some of the code:




this->_alarmPanelLed1 = new AlarmPanelLed(QPointF(-205,-225), "VHF1", Qt::red);
this->_alarmPanelScene->addItem(this->_alarmPanelLed1);

connect(this->_alarmPanelLed1, SIGNAL(lightChanged(bool)), this->_comThread, SLOT(lightChanged(bool)) );


And here is the error message i got:
Unhandled exception at 0x00430044 in hardwaretester.exe: 0xC000008C: Array bounds exceeded.

aamer4yu
23rd July 2008, 11:53
Are u using arrays ??
You are getting wrong index of array error.

mrnor3
23rd July 2008, 12:21
I am using a vector, but it should not matter here. If i comment out the connect sentence it runs fine. But else not. The debugger in Visual studio stops in the qobject.cpp.

More code:

alarmpanelled.h


#ifndef ALARMPANELLED_H
#define ALARMPANELLED_H

#include <QGraphicsItem>
#include <QFont>
#include <QFontMetrics>
#include <QObject>

class AlarmPanelLed : public QObject, public QGraphicsItem
{
Q_OBJECT
public:
AlarmPanelLed(QPointF &, QString, QColor);

signals:
void lightChanged(bool);

protected:
void paint ( QPainter *, const QStyleOptionGraphicsItem *, QWidget * );
QRectF boundingRect() const;
void mousePressEvent( QGraphicsSceneMouseEvent * event );

private:
QString _ledText;
QColor _textColor;
bool _lightOn;
QFont _font;
QFontMetrics _fontMetrics;
int _pixelsWide;
int _pixelsHigh;

};



#endif

hardwaretester.cpp (constructor)


#include "hardwaretester.h"
#include "cserialporthandler.h"
#include "comthread.h"
#include <iostream>
#include <QStringList>
#include <QGraphicsScene>
#include <QMessageBox>


HardwareTester::HardwareTester(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);

//Check if got in, in input a version string.
_inVersionString = false;

CSerialPortHandler handler;
handler.enumerate(this->_ports, false);
for(std::vector<_SSerialPortInfo>::const_iterator it = _ports.begin(); it != _ports.end(); ++it)
{
QString s;
s = (*it).strFriendlyName.c_str();
QString *qs = new QString();
qs->append((*it).strPortName.c_str());
qDebug( "Port name %s Friendly name: %s", qs->toAscii(), qPrintable( s ) );
delete qs;
_portList << s;
}


ui.comboBoxPorts->addItems(_portList);

_scene1 = new QGraphicsScene();

ui.graphicsView1->setScene(_scene1);
//Ensures that the view is always updated, no need for think about boundingRect.
ui.graphicsView1->setViewportUpdateMode(QGraphicsView::FullViewportU pdate);
//ui.graphicsView1->setBackgroundColor( Qt::black );


this->_panelRightOk = false;
this->_panelLeftOk = false;
this->_eblRightOk = false;
this->_eblLeftOk = false;
this->_gainRightOk = false;
this->_acRainRightOk = false;
this->_acRainLeftOk = false;
this->_acSeaRightOk = false;
this->_acSeaLeftOk = false;
this->_vrmRightOk = false;
this->_vrmLeftOk = false;
this->_rangeUpPressOk = false;
this->_rangeUpReleaseOk = false;
this->_rangeDownPressOk = false;
this->_rangeDownReleaseOk = false;
this->_centrePressOk = false;
this->_centreReleaseOk = false;
this->_ackAlarmPressOk = false;
this->_ackAlarmReleaseOk = false;
this->_tmrmPressOk = false;
this->_tmrmReleaseOk = false;
this->_truerelVectorsPressOk = false;
this->_truerelVectorsReleaseOk = false;

this->_lightTurnOffOk = false;
this->_lightTurnOnOk = false;

_dimBackLightsOk = false;


_PANEL = new ScrewButton(QPointF(-340,100), "PANEL");
_EBL = new ScrewButton(QPointF(-330,30), "EBL");
_GAIN = new ScrewButton(QPointF(-210,20), "GAIN");
_AC_RAIN = new ScrewButton(QPointF(-135,20), "A/C RAIN");
_AC_SEA = new ScrewButton(QPointF( -60,20), "A/C SEA");
_VRM = new ScrewButton(QPointF(15,35), "VRM");

_scene1->addItem(_PANEL);
_scene1->addItem(_EBL);
_scene1->addItem(_GAIN);
_scene1->addItem(_AC_RAIN);
_scene1->addItem(_AC_SEA);
_scene1->addItem(_VRM);

_RANGE_UP = new PushButton(QPointF(-275,20),"RANGE\nUP");
_RANGE_DOWN = new PushButton(QPointF(-275,100),"RANGE\nDOWN");
_CENTRE = new PushButton(QPointF(-210,100),"CENTRE");
_ACK_ALARM = new PushButton(QPointF(-135,100),"ACK\nALARM");
_TM_RM = new PushButton(QPointF(-60,100),"TM/RM");
_TRUE_REL_VECTORS = new PushButton(QPointF(15,100),"TRUE/REL\nVECTORS");;

_scene1->addItem(_RANGE_UP);
_scene1->addItem(_RANGE_DOWN);
_scene1->addItem(_CENTRE);
_scene1->addItem(_ACK_ALARM);
_scene1->addItem(_TM_RM);
_scene1->addItem(_TRUE_REL_VECTORS);

ui.pushButtonCloseConnection->setEnabled(false);
ui.pushButtonSend->setEnabled(false);
ui.pushButtonTurnOffLight->setEnabled(false);
ui.pushButtonTurnOnLight->setEnabled(false);
ui.horizontalSliderBackLights->setEnabled(false);
ui.pushButtonDoesDim->setEnabled(false);


//Start Alarm panel
_alarmPanelScene = new QGraphicsScene ( -250, -250, 250, 250);
ui.graphicsViewAlarmPanel->setScene(this->_alarmPanelScene);
ui.graphicsViewAlarmPanel->setViewportUpdateMode(QGraphicsView::FullViewportU pdate);

_speakerLine1 = new SpeakerLine(QPointF(-322,-245));
_speakerLine2 = new SpeakerLine(QPointF(-322,-230));
_speakerLine3 = new SpeakerLine(QPointF(-322,-215));
_speakerLine4 = new SpeakerLine(QPointF(-322,-200));
_speakerLine5 = new SpeakerLine(QPointF(-322,-185));
_speakerLine6 = new SpeakerLine(QPointF(-322,-170));
_speakerLine7 = new SpeakerLine(QPointF(-322,-155));

this->_alarmPanelScene->addItem(this->_speakerLine1);
this->_alarmPanelScene->addItem(this->_speakerLine2);
this->_alarmPanelScene->addItem(this->_speakerLine3);
this->_alarmPanelScene->addItem(this->_speakerLine4);
this->_alarmPanelScene->addItem(this->_speakerLine5);
this->_alarmPanelScene->addItem(this->_speakerLine6);
this->_alarmPanelScene->addItem(this->_speakerLine7);

_alarmPanelDisplay = new AlarmPanelDisplay(QPointF(-210,-245));
this->_alarmPanelScene->addItem(this->_alarmPanelDisplay);

this->_alarmPanelLed1 = new AlarmPanelLed(QPointF(-205,-225), "VHF1", Qt::red);
this->_alarmPanelScene->addItem(this->_alarmPanelLed1);

connect(this->_alarmPanelLed1, SIGNAL(lightChanged(bool)),this->_comThread, SLOT(lightChanged(bool)) );


this->_alarmPanelLed2 = new AlarmPanelLed(QPointF(-175,-225), "·", Qt::red);
this->_alarmPanelScene->addItem(this->_alarmPanelLed2);

this->_alarmPanelLed3 = new AlarmPanelLed(QPointF(-155,-225), "Distress", Qt::red);
this->_alarmPanelScene->addItem(this->_alarmPanelLed3);

this->_alarmPanelLed4 = new AlarmPanelLed(QPointF(-115,-225), "Fault", Qt::red);
this->_alarmPanelScene->addItem(this->_alarmPanelLed4);

this->_alarmPanelLed5 = new AlarmPanelLed(QPointF(-90,-225), "Test", Qt::green);
this->_alarmPanelScene->addItem(this->_alarmPanelLed5);

}



comthread.h


#ifndef COMTHREAD_H
#define COMTHREAD_H

#include <QThread>
#include <QMutex>
#include <QString>
#include <QVector>
#include <QTimer>
#include <iostream>
#include "cserialport.h"
#include "cserialporthandler.h"

class ComThread : public QThread
{
Q_OBJECT

public:
//Default constructor
ComThread(const QString);

//Destructor
~ComThread();

void run();
void send(QString& );

public slots:
void pollComPort();
void lightChanged(bool);
signals:
void charArrived(const char c);

private:
void writeStatus();
void parseInputByte( char c );


unsigned int _iLightLevel; // 1 = max light 8 = almost no light
bool _bStatusChanged; // To prevent repeaded updates when nothing is changed
bool _bInVersionString; // To allow any character when parsing the who is string
bool _bKeepAlive; // Set to true when the panel asks if we are still here
QString _panelIdentity;
bool _bAlarmLight;
std::vector<SSerialPortInfo> _ports;

bool _bFinished;
CSerialPort* _port;
QMutex _mutex; // Protects the variables _iLightLevel and _bStatusChanged which can be accessed from more than one thread
static const int INPUT_BUFSIZE = 255;
char _inputBuffer[ INPUT_BUFSIZE ];
QTimer comPortUpdateTimer;

};


#endif //COMTHREAD_H

mrnor3
23rd July 2008, 14:05
I think I've found the problem myself. The _comThread object was not initialized it means a NULL pointer. Thank you.