Confusing map problem

Hey, guys !

Firstly ... here are the files

https://docs.google.com/folder/d/0B06r_mXrdWb-elAwV0dlcVNFOG8/edit

addnote.h and addnote.cpp

in addnote.cpp there is a function void AddNote::on_deleteButton_clicked() that should normally delete an element from a map , however it gives me an error though it compiles alright :(

If you need any more info please say so :) and thanks in advance
Last edited on
Please post the relevant source code in the forum...what is the error exactly ?
Last edited on
These are the 2 functions I use when the button is clicked

1
2
3
4
5
6
7
void AddNote::on_deleteButton_clicked()
{
    if (vNote->find(ui->comboBox->currentText().toStdString()) != vNote->end())
        vNote->erase(vNote->find(ui->comboBox->currentText().toStdString())) ;

    repopCombo () ;
}


1
2
3
4
5
6
7
8
9
10
void AddNote::repopCombo()
{
    ui->comboBox->clear() ;
    ui->comboBox->addItem(tr("New")) ;

    for( std::map<std::string, Note>::iterator iter = vNote->begin() ; iter!=vNote->end(); iter++)
    {
        ui->comboBox->addItem(iter->second.getTitle()) ;
    }
}


So , the vNote map is alright , because I make several other actions with it and everything is fine except this one

This is how vNote is declared in AddNote class

std::map<std::string, Note> *vNote;

and this is the AddNote constructor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 AddNote::AddNote(QWidget *parent, std::map<std::string, Note> *nNote,int sdState) :
    QDialog(parent),
    ui(new Ui::AddNote),
    vNote (nNote)
{
    ui->setupUi(this);

    ui->beforeSdRadio->setEnabled(sdState) ;

    newNote.setH(0);
    newNote.setM(0);
    newNote.setS(0);

    newNote.setMode(AT_TIME) ;

    repopCombo () ;

}


The code compiles with no error , but at debug , when I click the delete button and trigger the appropriate function everything crashes and it gives me an error like "map/set iterator not dereferencable"
Can you show the definition for ui->comboBox->addItem()?
The problem is within the erase part because I use repopCombo in the constructor and there is no error , the only part where I get the error is at delete .
But here it is :
void QComboBox::addItem ( const QIcon & icon, const QString & text, const QVariant & userData = QVariant() )

Adds an item to the combobox with the given icon and text, and containing the specified userData (stored in the Qt::UserRole). The item is appended to the list of existing items.


From http://qt-project.org/doc/qt-4.8/qcombobox.html#addItem-2
This seems right to me...maybe try

1
2
3
auto findItr = vNote->find(ui->comboBox->currentText().toStdString();
if (findItr != vNote->end())
        vNote->erase(findItr) ;


Only thing I can think of is this is a race condition.
Last edited on
Ok ! :) I Will :D . Can you explain to me what auto is ?

Got it , nvm . It doesn't seem compulsory . And it still doesn't work .
Last edited on
Ok ! I finally solved it :)
It seems like though the error was realted to map/set iterator the part that caused it was the
ui->comboBox->clear() ;
It seems that before clearing the comboBox I had to disconnect all signal-slot bounds that involved this object :)
Last edited on
Topic archived. No new replies allowed.