Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QThread causes Sigsgev fault

QThread causes Sigsgev fault

Scheduled Pinned Locked Moved General and Desktop
qthreadnetworksigsegv
4 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nara
    wrote on last edited by
    #1

    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;
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      net_data seems to be a slot but then you emit it from the thread? It should be emit 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?

      N 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        net_data seems to be a slot but then you emit it from the thread? It should be emit 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?

        N Offline
        N Offline
        Nara
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nara
          wrote on last edited by
          #4

          Ok, I found my mistake, I was just dumb. I didn't initialize something properly but it looked like it was a bit random so I didnt get it first.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved