Results 1 to 4 of 4

Thread: Problem with connect()

  1. #1
    Join Date
    Jul 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Problem with connect()

    Hallo everybody.

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


    Qt Code:
    1. this->_alarmPanelLed1 = new AlarmPanelLed(QPointF(-205,-225), "VHF1", Qt::red);
    2. this->_alarmPanelScene->addItem(this->_alarmPanelLed1);
    3.  
    4. connect(this->_alarmPanelLed1, SIGNAL(lightChanged(bool)), this->_comThread, SLOT(lightChanged(bool)) );
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with connect()

    Are u using arrays ??
    You are getting wrong index of array error.

  3. #3
    Join Date
    Jul 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with connect()

    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
    Qt Code:
    1. #ifndef ALARMPANELLED_H
    2. #define ALARMPANELLED_H
    3.  
    4. #include <QGraphicsItem>
    5. #include <QFont>
    6. #include <QFontMetrics>
    7. #include <QObject>
    8.  
    9. class AlarmPanelLed : public QObject, public QGraphicsItem
    10. {
    11. Q_OBJECT
    12. public:
    13. AlarmPanelLed(QPointF &, QString, QColor);
    14.  
    15. signals:
    16. void lightChanged(bool);
    17.  
    18. protected:
    19. void paint ( QPainter *, const QStyleOptionGraphicsItem *, QWidget * );
    20. QRectF boundingRect() const;
    21. void mousePressEvent( QGraphicsSceneMouseEvent * event );
    22.  
    23. private:
    24. QString _ledText;
    25. QColor _textColor;
    26. bool _lightOn;
    27. QFont _font;
    28. QFontMetrics _fontMetrics;
    29. int _pixelsWide;
    30. int _pixelsHigh;
    31.  
    32. };
    33.  
    34.  
    35.  
    36. #endif
    To copy to clipboard, switch view to plain text mode 
    hardwaretester.cpp (constructor)
    Qt Code:
    1. #include "hardwaretester.h"
    2. #include "cserialporthandler.h"
    3. #include "comthread.h"
    4. #include <iostream>
    5. #include <QStringList>
    6. #include <QGraphicsScene>
    7. #include <QMessageBox>
    8.  
    9.  
    10. HardwareTester::HardwareTester(QWidget *parent, Qt::WFlags flags)
    11. : QMainWindow(parent, flags)
    12. {
    13. ui.setupUi(this);
    14.  
    15. //Check if got in, in input a version string.
    16. _inVersionString = false;
    17.  
    18. CSerialPortHandler handler;
    19. handler.enumerate(this->_ports, false);
    20. for(std::vector<_SSerialPortInfo>::const_iterator it = _ports.begin(); it != _ports.end(); ++it)
    21. {
    22. s = (*it).strFriendlyName.c_str();
    23. QString *qs = new QString();
    24. qs->append((*it).strPortName.c_str());
    25. qDebug( "Port name %s Friendly name: %s", qs->toAscii(), qPrintable( s ) );
    26. delete qs;
    27. _portList << s;
    28. }
    29.  
    30.  
    31. ui.comboBoxPorts->addItems(_portList);
    32.  
    33. _scene1 = new QGraphicsScene();
    34.  
    35. ui.graphicsView1->setScene(_scene1);
    36. //Ensures that the view is always updated, no need for think about boundingRect.
    37. ui.graphicsView1->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    38. //ui.graphicsView1->setBackgroundColor( Qt::black );
    39.  
    40.  
    41. this->_panelRightOk = false;
    42. this->_panelLeftOk = false;
    43. this->_eblRightOk = false;
    44. this->_eblLeftOk = false;
    45. this->_gainRightOk = false;
    46. this->_acRainRightOk = false;
    47. this->_acRainLeftOk = false;
    48. this->_acSeaRightOk = false;
    49. this->_acSeaLeftOk = false;
    50. this->_vrmRightOk = false;
    51. this->_vrmLeftOk = false;
    52. this->_rangeUpPressOk = false;
    53. this->_rangeUpReleaseOk = false;
    54. this->_rangeDownPressOk = false;
    55. this->_rangeDownReleaseOk = false;
    56. this->_centrePressOk = false;
    57. this->_centreReleaseOk = false;
    58. this->_ackAlarmPressOk = false;
    59. this->_ackAlarmReleaseOk = false;
    60. this->_tmrmPressOk = false;
    61. this->_tmrmReleaseOk = false;
    62. this->_truerelVectorsPressOk = false;
    63. this->_truerelVectorsReleaseOk = false;
    64.  
    65. this->_lightTurnOffOk = false;
    66. this->_lightTurnOnOk = false;
    67.  
    68. _dimBackLightsOk = false;
    69.  
    70.  
    71. _PANEL = new ScrewButton(QPointF(-340,100), "PANEL");
    72. _EBL = new ScrewButton(QPointF(-330,30), "EBL");
    73. _GAIN = new ScrewButton(QPointF(-210,20), "GAIN");
    74. _AC_RAIN = new ScrewButton(QPointF(-135,20), "A/C RAIN");
    75. _AC_SEA = new ScrewButton(QPointF( -60,20), "A/C SEA");
    76. _VRM = new ScrewButton(QPointF(15,35), "VRM");
    77.  
    78. _scene1->addItem(_PANEL);
    79. _scene1->addItem(_EBL);
    80. _scene1->addItem(_GAIN);
    81. _scene1->addItem(_AC_RAIN);
    82. _scene1->addItem(_AC_SEA);
    83. _scene1->addItem(_VRM);
    84.  
    85. _RANGE_UP = new PushButton(QPointF(-275,20),"RANGE\nUP");
    86. _RANGE_DOWN = new PushButton(QPointF(-275,100),"RANGE\nDOWN");
    87. _CENTRE = new PushButton(QPointF(-210,100),"CENTRE");
    88. _ACK_ALARM = new PushButton(QPointF(-135,100),"ACK\nALARM");
    89. _TM_RM = new PushButton(QPointF(-60,100),"TM/RM");
    90. _TRUE_REL_VECTORS = new PushButton(QPointF(15,100),"TRUE/REL\nVECTORS");;
    91.  
    92. _scene1->addItem(_RANGE_UP);
    93. _scene1->addItem(_RANGE_DOWN);
    94. _scene1->addItem(_CENTRE);
    95. _scene1->addItem(_ACK_ALARM);
    96. _scene1->addItem(_TM_RM);
    97. _scene1->addItem(_TRUE_REL_VECTORS);
    98.  
    99. ui.pushButtonCloseConnection->setEnabled(false);
    100. ui.pushButtonSend->setEnabled(false);
    101. ui.pushButtonTurnOffLight->setEnabled(false);
    102. ui.pushButtonTurnOnLight->setEnabled(false);
    103. ui.horizontalSliderBackLights->setEnabled(false);
    104. ui.pushButtonDoesDim->setEnabled(false);
    105.  
    106.  
    107. //Start Alarm panel
    108. _alarmPanelScene = new QGraphicsScene ( -250, -250, 250, 250);
    109. ui.graphicsViewAlarmPanel->setScene(this->_alarmPanelScene);
    110. ui.graphicsViewAlarmPanel->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    111.  
    112. _speakerLine1 = new SpeakerLine(QPointF(-322,-245));
    113. _speakerLine2 = new SpeakerLine(QPointF(-322,-230));
    114. _speakerLine3 = new SpeakerLine(QPointF(-322,-215));
    115. _speakerLine4 = new SpeakerLine(QPointF(-322,-200));
    116. _speakerLine5 = new SpeakerLine(QPointF(-322,-185));
    117. _speakerLine6 = new SpeakerLine(QPointF(-322,-170));
    118. _speakerLine7 = new SpeakerLine(QPointF(-322,-155));
    119.  
    120. this->_alarmPanelScene->addItem(this->_speakerLine1);
    121. this->_alarmPanelScene->addItem(this->_speakerLine2);
    122. this->_alarmPanelScene->addItem(this->_speakerLine3);
    123. this->_alarmPanelScene->addItem(this->_speakerLine4);
    124. this->_alarmPanelScene->addItem(this->_speakerLine5);
    125. this->_alarmPanelScene->addItem(this->_speakerLine6);
    126. this->_alarmPanelScene->addItem(this->_speakerLine7);
    127.  
    128. _alarmPanelDisplay = new AlarmPanelDisplay(QPointF(-210,-245));
    129. this->_alarmPanelScene->addItem(this->_alarmPanelDisplay);
    130.  
    131. this->_alarmPanelLed1 = new AlarmPanelLed(QPointF(-205,-225), "VHF1", Qt::red);
    132. this->_alarmPanelScene->addItem(this->_alarmPanelLed1);
    133.  
    134. connect(this->_alarmPanelLed1, SIGNAL(lightChanged(bool)),this->_comThread, SLOT(lightChanged(bool)) );
    135.  
    136.  
    137. this->_alarmPanelLed2 = new AlarmPanelLed(QPointF(-175,-225), "·", Qt::red);
    138. this->_alarmPanelScene->addItem(this->_alarmPanelLed2);
    139.  
    140. this->_alarmPanelLed3 = new AlarmPanelLed(QPointF(-155,-225), "Distress", Qt::red);
    141. this->_alarmPanelScene->addItem(this->_alarmPanelLed3);
    142.  
    143. this->_alarmPanelLed4 = new AlarmPanelLed(QPointF(-115,-225), "Fault", Qt::red);
    144. this->_alarmPanelScene->addItem(this->_alarmPanelLed4);
    145.  
    146. this->_alarmPanelLed5 = new AlarmPanelLed(QPointF(-90,-225), "Test", Qt::green);
    147. this->_alarmPanelScene->addItem(this->_alarmPanelLed5);
    148.  
    149. }
    To copy to clipboard, switch view to plain text mode 

    comthread.h
    Qt Code:
    1. #ifndef COMTHREAD_H
    2. #define COMTHREAD_H
    3.  
    4. #include <QThread>
    5. #include <QMutex>
    6. #include <QString>
    7. #include <QVector>
    8. #include <QTimer>
    9. #include <iostream>
    10. #include "cserialport.h"
    11. #include "cserialporthandler.h"
    12.  
    13. class ComThread : public QThread
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. //Default constructor
    19. ComThread(const QString);
    20.  
    21. //Destructor
    22. ~ComThread();
    23.  
    24. void run();
    25. void send(QString& );
    26.  
    27. public slots:
    28. void pollComPort();
    29. void lightChanged(bool);
    30. signals:
    31. void charArrived(const char c);
    32.  
    33. private:
    34. void writeStatus();
    35. void parseInputByte( char c );
    36.  
    37.  
    38. unsigned int _iLightLevel; // 1 = max light 8 = almost no light
    39. bool _bStatusChanged; // To prevent repeaded updates when nothing is changed
    40. bool _bInVersionString; // To allow any character when parsing the who is string
    41. bool _bKeepAlive; // Set to true when the panel asks if we are still here
    42. QString _panelIdentity;
    43. bool _bAlarmLight;
    44. std::vector<SSerialPortInfo> _ports;
    45.  
    46. bool _bFinished;
    47. CSerialPort* _port;
    48. QMutex _mutex; // Protects the variables _iLightLevel and _bStatusChanged which can be accessed from more than one thread
    49. static const int INPUT_BUFSIZE = 255;
    50. char _inputBuffer[ INPUT_BUFSIZE ];
    51. QTimer comPortUpdateTimer;
    52.  
    53. };
    54.  
    55.  
    56. #endif //COMTHREAD_H
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Problem with connect()

    I think I've found the problem myself. The _comThread object was not initialized it means a NULL pointer. Thank you.

Similar Threads

  1. Problem with connect() (enum-type as parameter)
    By alu23 in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:46
  2. connect problem QDialog
    By Zergi in forum Newbie
    Replies: 1
    Last Post: 1st January 2008, 13:36
  3. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  4. Very simple problem with QServerSocket and Qsocket
    By eter in forum Qt Programming
    Replies: 2
    Last Post: 4th November 2006, 08:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.