App crash on emitting signal



  • Hi everyone,

    In my app I emit a signal when a variable in TaskGraphicsScene (QGraphicsScene custom class) is changed:

    //TaskGraphicsScene.cpp
    void TaskGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *btnReleased){
      if(btnReleased->button() == Qt::LeftButton){
          //view as current node
          *currentPointer = taskShown;
          emit changeTask();
      }
    }
    

    When the signal is recieved by the MainWindow class, the app crashes.

    I have seen this post but I don't know how to "so i moved signals into the graphics item class and added a getter function to the graphics view which returns a pointer to that graphics item. now, main widget will get signals directly from the graphics item." as the OP did.

    Any tip or clue?? Thank you.



  • Hi, can you post your connection



  • This is my connection, I have 12 TaskGraphicsScenes in the UI:

        for(unsigned i= 0; i < 12; i++){
          connect(childrenScenes[i], SIGNAL(changeTask()), this, SLOT(on_taskChanged()));
        }
    
    

  • Moderators

    @TagLog said in App crash on emitting signal:

    on_taskChanged

    What does on_taskChange do? Did you try to use debugger to go step by step through it to see where exactly it crashes and why?



  • Hi,

    check the return status of connect statement.
    and check logs in slot() and function where ur emmitting signal();

    Thanks,



  • on_taskChanged() slot must be culprit here. You can focus on the code inside the slot. You can use debugger to look at the issue as @jslum already suggested.



  • @jsulm It call another function called updateWindow(), but that function is also called by other buttons and stuff, so the problem is in the connection/signal/slot


  • Lifetime Qt Champion

    Hi,

    Please post the stack trace of your crash, that should help pinpoint the problem.



  • @SGaist

    This is the stack trace (as a newbie, I think the problem could be in thread 1, the last one in the stack trace), in a breakpoint the debugger says this message: Disassembler failed: Cannot access memory at address 0x6a85097c, the function is unknown (??)


  • Moderators

    @TagLog
    Can you show the content of following methods:

    • MainWindow::updateTree
    • MainWindow::updateWindow
    • MainWindow::on_taskChanged
      ?


  • @jsulm
    Here you go:

    void MainWindow::on_taskChanged(){
      updateWindow();
    }
    
    void MainWindow::updateWindow()
    {
    
      currentScene->clear();
    
      for (unsigned i = 0; i < 12; i ++){
          childrenScenes[i]->clear();
      }
    
      ui->btnModify->setEnabled(true);
      ui->btnComplete->setEnabled(true);
      ui->btnAddChild->setEnabled(true);
    
      ui->lblProjectTitle->setText(currentProj.getTitle());
      ui->lblCurrentTitle->setText(currentTask->getTitle());
      ui->tedCurrentText->setText(currentTask->getText());
    
      currentTask->drawAsCurrent(currentScene);
    
      for(unsigned i = 0; i < 12 && i < currentTask->getChildren().size(); i++){
          childrenScenes[i]->setTaskShown(currentTask->getChildren()[i] );
          childrenScenes[i]->drawTaskShown();
      }
      updateTree();
    }
    
    void MainWindow::updateTree(){
    
      QString TaskTree;
      Task* masterPointer = currentTask;
    
      while(masterPointer != Q_NULLPTR){
          TaskTree = "/" + masterPointer->getTitle() + TaskTree;
          masterPointer = currentTask->getMaster();
      }
    
      ui->lblDepTree->setText(TaskTree);
    }
    

    I'm willing for any explanation if you need



  • First suspects are the following:

     for (unsigned i = 0; i < 12; i ++){
          childrenScenes[i]->clear();
      }
    

    and

      for(unsigned i = 0; i < 12 && i < currentTask->getChildren().size(); i++){
          childrenScenes[i]->setTaskShown(currentTask->getChildren()[i] );
          childrenScenes[i]->drawTaskShown();
      }
    

    Are you confident thay you remain in bounds here? for both containers (currentTask->getChildren() and childrenScenes)?

    EDIT: also, what is

    currentTask
    

    ? Is it set properly?



  • If you make assumptions in your code, assert them (even static assert them if you can)

    • is currentTask null?
    • is currentScene null?
    • is childrenScenes of size >=12
    • is any childrenScenes[i] null

    The easiest way to debug this is put a breakpoint at the first line of on_taskChanged and step into/over every line untill you find exactly where it explodes and fix whatever is wrong there



  • @BjornW In this test case I remain in bounds in those lines of code.

    currentTask is a pointer to a custom class object which is initialized at the beginnning of the test.



  • @VRonin said in App crash on emitting signal:

    The easiest way to debug this is put a breakpoint at the first line of on_taskChanged and step into/over every line untill you find exactly where it explodes and fix whatever is wrong there



  • @VRonin I'm doing this right now, as soon as I finish I'll tell you what I found

    Edit: I can't find anything now, but for few days I can't look at the code, I'll continue to look ASAP



  • @VRonin

    I finally found what caused crashes: it was the UpdateTree function. I wrote a wrong line which caused an infinite loop. I'm feeling both stupid and happy :) / :(


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.