PDA

View Full Version : connect() terminates the program



saman_artorious
3rd March 2013, 08:49
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()


void Control::initObjects()
{
logger = new ErrorLogger();

X = new Xr();

Y = new Y();

Z = new Z();

rs_485 = new rs485();

establishConnections();
}

void Control::establishConnections()
{
connect(X , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));
connect(Y , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));
connect(Z , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));
connect(rs485 , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));
}



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

alizadeh91
3rd March 2013, 09:13
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

saman_artorious
3rd March 2013, 09:15
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.

alizadeh91
3rd March 2013, 09:22
Seems somethings wrong with rs_485. Can't tell what is it unless you provide a simple example (attach simple source code)

saman_artorious
3rd March 2013, 10:56
update: I found this warning in debug


&"warning: GDB: Failed to set controlling terminal: Inappropriate ioctl for device\n"



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


0 QMetaObject::activate(QObject*, int, int, void**) /home/saman/Qt5.0.1/5.0.1/gcc/lib/libQt5Core.so.5 0xb735c540
1 QMetaObject::activate(QObject*, QMetaObject const*, int, void**) /home/saman/Qt5.0.1/5.0.1/gcc/lib/libQt5Core.so.5 0xb735d21b
2 rs485::logMessage moc_rs485.cpp 153 0x8064c12
3 rs485::logConstruction rs485.cpp 498 0x805661d
4 MainWindow::MainWindow mainwindow.cpp 27 0x804e8c0
5 main main.cpp 9 0x804e5f0

Debugging gives me this:


void rs485::logMessage(const char * _t1)
{
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 0, _a);
}



inside rs I have defined a signal

signals:
void logMessage(const char* );

After rs object creation, I call its member function to trigger a sample signal for the logger to catch:

void rs485::logConstruction()
{
emit logMessage("RS485 constructed:)");
}

(this is done inside MainWindow):

connect(rs_485 , SIGNAL(logMessage(const char* )), logger, SLOT(logMessage(const char* )));

rs_485->printHello();
rs_485->logConstruction();


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.

amleto
3rd March 2013, 13:04
oh right! :rolleyes: What's that got to do with emit logMessage(...)?

please read my sig for future reference!

saman_artorious
3rd March 2013, 18:25
oh right! :rolleyes: 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.



bool rs485::rs485ConfigPort()
{
termios portSettings;

memset(&portSettings, 0, sizeof(portSettings));

portSettings.c_cflag |= (CLOCAL | CREAD);

cfsetispeed(&portSettings, B57600);

portSettings.c_cflag &= ~PARENB;

portSettings.c_cflag |= CS8;

portSettings.c_cflag &= ~CSIZE;

portSettings.c_cflag &= ~CSTOPB; //stop bit = 1

//cfmakeraw(&portSettings);

if (tcsetattr(fd, TCSANOW, &portSettings))
{
emit logMessage("Can not adjust port settings");

close(fd);
return false;
}

tcflush(fd, TCIFLUSH);
return true;
}

alizadeh91
3rd March 2013, 18:41
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.

saman_artorious
3rd March 2013, 19:02
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.