Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QThread causes Sigsgev fault

    General and Desktop
    qthread network sigsegv
    2
    4
    1206
    Loading More Posts
    • 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
      Nara last edited by

      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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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 Reply Quote 0
        • N
          Nara @Chris Kawa last edited by

          @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 Reply Quote 0
          • N
            Nara last edited by

            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 Reply Quote 0
            • First post
              Last post