I develop and compile on RedHat 7.4 with GCC 4.8.5 and Qt 4.8.5. The code has to be statically linked. Then executed on a virtual machine running Scientific Linux release 6.7. memcpy-Wrap is used in order to prevent dependencies on newer GLIBC >= 2.4
I have the following MWE:
#include <iostream>
#include <unistd.h>
#include <QtCore>
#include <QThread>
__asm__(".symver memcpy, memcpy@GLIBC_2.2.5");
extern "C" {
void *__wrap_memcpy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); }
}
class Worker : public QThread {
void run() {
std::cout << "WORKER: Started." << std::endl;
QObject::connect(this, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit()));
int i=0;
while(i++<3) {
std::cout << "WORKER: I am running." << std::endl;
usleep(1e6);
}
std::cout << "WORKER: Finished." << std::endl;
}
};
int main(int argc, char** argv) {
std::cout << "MAIN: Init QCoreApplication" << std::endl;
QCoreApplication qtApplication(argc, argv);
std::cout << "MAIN: Init Worker" << std::endl;
Worker myWorker;
myWorker.start();
std::cout << "MAIN: Start Event-Loop." << std::endl;
qtApplication.exec();
std::cout << "MAIN: Event-Loop finished." << std::endl;
return 0;
}
This code is compiled on the RedHat-System with
g++ -I$QTD/mkspecs/linux-g++ -I$QTD/include -I$QTD/include/QtCore -o mwe mwe.cpp -Wl,--wrap=memcpy -L$QTD/lib/ -lQtCore -lQtNetwork -lglib-2.0 -lrt -lpthread -ldl -lz
where $QTD holds my installation of my Qt-4.8.5.
The following behavior is expected and observed on the Red-Hat-System:
MAIN: Init QCoreApplication
MAIN: Init Worker
MAIN: Start Event-Loop.
WORKER: Started.
WORKER: I am running.
WORKER: I am running.
WORKER: I am running.
WORKER: Finished.
MAIN: Event-Loop finished.
The following behavior is observed on the Scientific-Linux-System:
MAIN: Init QCoreApplication
MAIN: Init Worker
MAIN: Start Event-Loop.
WORKER: Started.
WORKER: I am running.
WORKER: I am running.
WORKER: I am running.
WORKER: Finished.
And then the application never finishes.
It seems that in the Red-Hat-System, the finished-signal from the worker-thread is connected to the quit-slot in the core application. This doesn't seem to happen in the Scientific-Linux-System. Does anyone have any advice why this happens and how I can debug it?