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. Program exiting when closing QTcpServer and socket with a QPushButton
QtWS25 Last Chance

Program exiting when closing QTcpServer and socket with a QPushButton

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt4.7.4tcppush buttonsigsegv
2 Posts 2 Posters 406 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.
  • S Offline
    S Offline
    stordd
    wrote on last edited by
    #1

    Hello !

    I have a program that communicates via Tcp .(I'm on Qt4.7)
    img_dune.PNG

    This is my class IHM's form that herits from QWidget. When I click on the launch button my program starts, creates a QTcpServer that connects to a distant client and a QTcpSocket connecting to a distant TcpServer and they exchange messages.
    (This is dealt in an other class)

    Then I tried to add a initialize button that would close the sockets and clear the contents of my QTableWidget
    In my IHM.cpp :

    void IHM::on_initialize_clicked()
    {
        QMessageBox msgBox;
        msgBox.setWindowTitle("Initialization");
        msgBox.setText("Are you sure you want to (re)initialize DUNE ? ");
        msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        int ret = msgBox.exec();
        msgBox.clickedButton();
        switch(ret)
        {
        case QMessageBox::Yes:
            ui->buttonLaunch->setChecked(false);
            ui->tableWidget->clearContents();
            ui->tableWidget->setRowCount(0);
            ui->tacticalPort->setEnabled(false);
            ui->tacticalIP->setEnabled(false);
            ui->comboBox->setCurrentIndex(0);
    
            if (ui->tableWidget2->isEnabled())
            {
                ui->tableWidget2->clearContents();
                ui->tableWidget2->setRowCount(0);
                ui->tableWidget2->setEnabled(false);
            }
            else {
            }
            if (server->getServerNrs() != NULL)
            {
                server->getServerNrs()->deleteLater();
            }
            else {
            }
            if(server->getSocketTechnique() != NULL)
            {
                server->getSocketTechnique()->close();
                server->getSocketTechnique()->deleteLater();
            }
            else {
            }
            if(server->getSocketTactique() != NULL)
            {
                server->getSocketTactique()->close();
                server->getSocketTactique()->deleteLater();
            }
            else {
            }
            if(server->getSocketServer() != NULL)
            {
                server->getSocketServer()->close();
                server->getSocketServer()->deleteLater();
            }
            else {
            }
            break;
        case QMessageBox::No:
            msgBox.close();
            break;
        }
    }
    

    But then when I click on the yes button on my message box my program closes and i don't know why.

    Here is my main.cpp :

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
       IHM ihm;
       ihm.show();
      return a.exec();
    }
    

    When I tried to debug :
    Sometimes it went throught all my void IHM::on_initialize_clicked() function
    and then went looping on the return a.exec() and exits with a :
    SIGSEGV
    Segmentation fault
    and the other times it exited at the line server->getSocketServer()->deleteLater();with the same error.

    I have no idea why and hope someone could help me. Thanks !

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      99.9999% probability you are trying to use the object you just deleted.
      If you call deleteLater on an object you then have to recreate it (e.g. with new) before using it or trying to delete it again

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      7

      • Login

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