QThread causes Sigsgev fault
-
Hello,
I have a problem, I'm trying to make a multi threaded app and when I create my threads it causes a sigsegv fault, sometimes directly, sometimes later, sometimes not at all.
I'm overriding the run method of the QThread in class because it's more practice for me.Here's the creation of the threads :
Listener_Thread* lt = new Listener_Thread(client); QObject::connect(lt,SIGNAL(data_received(std::string)),this,SLOT(net_data(std::string))); lt->start(); listener_threads.push_back(lt);
The run method :
std::string data = ""; while(true) { data = net1->Receive(); if(data != "") emit net_data(data); }
The net1->Receive() method :
string data = ""; sf::Packet pack; if(socket->receive(pack) != sf::Socket::Done) // Error else pack >> data; return data;
-
net_data
seems to be a slot but then you emit it from the thread? It should beemit data_received(data);
. Or is this just a typo in here and your code doesn't really do that?Other than that - how do you exit the
while(true)
loop or is this a stripped version of your program? -
@Chris-Kawa I'm sorry it was tricky because I was testing stuff and I had the slot net_data in my thread class and in my main class and I called the net_data slot which just emitted the data_received.
For the while(true) I wanted to do this when it worked but I just added a while(!stop) where stop is a bool variable.
Could it be because I don't delete the threads ? How could I do that ? The listener thread runs all the time and I start the sending thread everytime I need to send something, so I can't (I guess) delete these with a finished signal connected to a deleteLater.