Results 1 to 9 of 9

Thread: connect() terminates the program

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default connect() terminates the program

    I get a weird program termination when I use connect() in my code. I checked the code properly, i don't know where the mistake comes from:

    I call construct the control object in MainWindow and call its init()
    Qt Code:
    1. void Control::initObjects()
    2. {
    3. logger = new ErrorLogger();
    4.  
    5. X = new Xr();
    6.  
    7. Y = new Y();
    8.  
    9. Z = new Z();
    10.  
    11. rs_485 = new rs485();
    12.  
    13. establishConnections();
    14. }
    15.  
    16. void Control::establishConnections()
    17. {
    18. connect(X , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));
    19. connect(Y , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));
    20. connect(Z , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));
    21. connect(rs485 , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));
    22. }
    To copy to clipboard, switch view to plain text mode 

    the last connect terminates my program, thought the first 3 work properly.

  2. #2
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: connect() terminates the program

    Can't be because of rs485!!?? because you've made an object with name of rs_485. but you have used it with name of rs485 which is the class name. That could be the mistake

  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: connect() terminates the program

    Quote Originally Posted by alizadeh91 View Post
    Can't be because of rs485!!?? because you've made an object with name of rs_485. but you have used it with name of rs485 which is the class name. That could be the mistake
    That was changed after pasting. it still jumps out when it is run.

  4. #4
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: connect() terminates the program

    Seems somethings wrong with rs_485. Can't tell what is it unless you provide a simple example (attach simple source code)

  5. #5
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: connect() terminates the program

    update: I found this warning in debug
    Qt Code:
    1. &"warning: GDB: Failed to set controlling terminal: Inappropriate ioctl for device\n"
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by alizadeh91 View Post
    Seems somethings wrong with rs_485. Can't tell what is it unless you provide a simple example (attach simple source code)
    Qt Code:
    1. 0 QMetaObject::activate(QObject*, int, int, void**) /home/saman/Qt5.0.1/5.0.1/gcc/lib/libQt5Core.so.5 0xb735c540
    2. 1 QMetaObject::activate(QObject*, QMetaObject const*, int, void**) /home/saman/Qt5.0.1/5.0.1/gcc/lib/libQt5Core.so.5 0xb735d21b
    3. 2 rs485::logMessage moc_rs485.cpp 153 0x8064c12
    4. 3 rs485::logConstruction rs485.cpp 498 0x805661d
    5. 4 MainWindow::MainWindow mainwindow.cpp 27 0x804e8c0
    6. 5 main main.cpp 9 0x804e5f0
    To copy to clipboard, switch view to plain text mode 

    Debugging gives me this:
    Qt Code:
    1. void rs485::logMessage(const char * _t1)
    2. {
    3. void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
    4. QMetaObject::activate(this, &staticMetaObject, 0, _a);
    5. }
    To copy to clipboard, switch view to plain text mode 

    inside rs I have defined a signal
    Qt Code:
    1. signals:
    2. void logMessage(const char* );
    To copy to clipboard, switch view to plain text mode 

    After rs object creation, I call its member function to trigger a sample signal for the logger to catch:
    Qt Code:
    1. void rs485::logConstruction()
    2. {
    3. emit logMessage("RS485 constructed:)");
    4. }
    To copy to clipboard, switch view to plain text mode 

    (this is done inside MainWindow):
    Qt Code:
    1. connect(rs_485 , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));
    2.  
    3. rs_485->printHello();
    4. rs_485->logConstruction();
    To copy to clipboard, switch view to plain text mode 


    printHello Member works fine, but.... log construction jumps out!


    Added after 25 minutes:


    i found the problem,
    tcsetattr(fd, TCSANOW, &portSettings) cannot succeed, it fails and closes the device.
    that's why connect jumps outta program.
    Last edited by saman_artorious; 3rd March 2013 at 10:56.

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: connect() terminates the program

    oh right! What's that got to do with emit logMessage(...)?

    please read my sig for future reference!
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. The following user says thank you to amleto for this useful post:

    alizadeh91 (3rd March 2013)

  8. #7
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: connect() terminates the program

    Quote Originally Posted by amleto View Post
    oh right! What's that got to do with emit logMessage(...)?

    please read my sig for future reference!
    because that terminated the program when I was trying to connect the object with another! though, the object is created successfully.
    this is because tcsetattr() function gives back Input/Output error.

    Well, this is a linux device problem, I will handle it myself. Thanks anyway.

    Qt Code:
    1. bool rs485::rs485ConfigPort()
    2. {
    3. termios portSettings;
    4.  
    5. memset(&portSettings, 0, sizeof(portSettings));
    6.  
    7. portSettings.c_cflag |= (CLOCAL | CREAD);
    8.  
    9. cfsetispeed(&portSettings, B57600);
    10.  
    11. portSettings.c_cflag &= ~PARENB;
    12.  
    13. portSettings.c_cflag |= CS8;
    14.  
    15. portSettings.c_cflag &= ~CSIZE;
    16.  
    17. portSettings.c_cflag &= ~CSTOPB; //stop bit = 1
    18.  
    19. //cfmakeraw(&portSettings);
    20.  
    21. if (tcsetattr(fd, TCSANOW, &portSettings))
    22. {
    23. emit logMessage("Can not adjust port settings");
    24.  
    25. close(fd);
    26. return false;
    27. }
    28.  
    29. tcflush(fd, TCIFLUSH);
    30. return true;
    31. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by saman_artorious; 3rd March 2013 at 18:45.

  9. #8
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: connect() terminates the program

    We are not mind reader!!! Here is a forum for Qt programming, so you can ask your questions about Qt Framework and anything related to it. Your question is not actually related to Qt.

  10. #9
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: connect() terminates the program

    Quote Originally Posted by alizadeh91 View Post
    We are not mind reader!!! Here is a forum for Qt programming, so you can ask your questions about Qt Framework and anything related to it. Your question is not actually related to Qt.
    You are right, I did not know this before I found the problem, I thought it was related to QObjects. anyway, I solved the problem, it was a device problem.

Similar Threads

  1. Replies: 3
    Last Post: 29th January 2014, 12:03
  2. Replies: 6
    Last Post: 25th November 2010, 21:02
  3. Replies: 8
    Last Post: 26th March 2010, 12:45
  4. program cannot connect to X server
    By Wazman in forum Qt Programming
    Replies: 3
    Last Post: 1st September 2009, 19:28
  5. how can i connect program to phonism
    By motsh in forum Qt Programming
    Replies: 0
    Last Post: 6th May 2009, 15:33

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
  •  
Qt is a trademark of The Qt Company.