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. QModelIndex selection causes application crash
Forum Updated to NodeBB v4.3 + New Features

QModelIndex selection causes application crash

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 664 Views 2 Watching
  • 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.
  • M Offline
    M Offline
    mourad_bilog
    wrote on last edited by
    #1

    Hello everybody,

    I've a strange crashe with QModelIndex. In fact all comments are written into log file but application crashes.

    frmPatient *w = new frmPatient(this,0);
    	
    	if(w->exec())
    	{
    		int patient = w->currentPatient();
    	
    		WriteIntoLogFile(QString("création du patient n° %1").arg(patient));
    		if(patient != 0)
    		{
    			WriteIntoLogFile("raffraichissmeent liste patient");
    
    			showPatients("");
    		
    			WriteIntoLogFile(QString("sélection du patient n° %1 dans la liste").arg(QString::number(patient)));
    			
    			QAbstractItemModel* model = tabPatient->model();  
    			if (model == 0)
    				WriteIntoLogFile("echec sélection du modèle depuis la liste des patients");
    
    			QModelIndex start(model->index(0,0,QModelIndex()));
    			if (!start.isValid())
    				WriteIntoLogFile("echec sélection modèle index dans la liste");
    
    			QModelIndexList list = model->match(start, Qt::DisplayRole, patient);
    			if (list.isEmpty())
    				WriteIntoLogFile(QString("sélection du patient n° %1 dans la liste").arg(QString::number(patient)));
    
    			if(!list.isEmpty())
    			{
    				WriteIntoLogFile("sélection de l'élement dans la liste");
    				tabPatient->setCurrentIndex(list[0]);
    				WriteIntoLogFile("CurrentIndex sélectionné");
    				tabPatient->scrollTo(model->index(list[0].row(), 1));	
    				WriteIntoLogFile("scrollTo l'élement"); // this comment is written into log file and application crashes
    			}	
    			else
    				WriteIntoLogFile("l'élement à selectionner est vide");
    		}
    	}
    
    	WriteIntoLogFile("suppression objet");
    	delete w;
    

    I'm on Qt4.8 and the crashes happens only Windows 10 x64.

    Can anyone tell me what's wrong ?

    Many thanks in advance.
    Regards.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      if you single step, what line does it crash in?

      One note though
      you create (dialog`) frmPatient(this,0); with parent as "this"
      but you delete it later yourself. So parent might also try to delete it
      on closing.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        To add to @mrjj, you are testing if model is equal zero, if so you write some log and then go on using it, that will surely crash. You should stop there.

        By the way, there's no need for frmPatnient to be allocated on the heap since you destroy it at the end anyway. Just allocate it on the stack.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

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