Re: RTab-Map closes unexpectedly when I'm trying to save database

Posted by mcb9216 on
URL: http://official-rtab-map-forum.206.s1.nabble.com/RTab-Map-closes-unexpectedly-when-I-m-trying-to-save-database-tp1149p1312.html

Hello again, with my teamwork, this problem was solved for us.
Analising the bug, we found that it was an error with QT interfaces, We don't know how to explain well
However, we removed the window that asked where the database is going to be saved and the name of the databse file.
Now, everytime something is mapped and the bottom "Close database" is pushed, the database file is always saved automatically in the same dir (/home/cristina/Documents/RTAB-Map) with the default name.

For doing this, the file /guilib/src/MainWindow.cpp was modified.

Code:

//all includes before

#include <exception>
using namespace std;

.............

namespace rtabmap {

struct MyException : public exception
{
  const char * what () const throw ()
  {
    return "C++ Exception";
  }
};

.............

bool MainWindow::closeDatabase()
{
        if(_state != MainWindow::kInitialized)
        {
                UERROR("This method can be called only in INITIALIZED state.");
                return false;
        }

        _newDatabasePathOutput.clear();
        if(!_newDatabasePath.isEmpty() && _databaseUpdated)
        {
                QMessageBox::Button b = QMessageBox::question(this,
                                tr("Save database"),
                                tr("Save the new database?"),
                                QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Discard,
                                QMessageBox::Save);

                if(b == QMessageBox::Save)
                {
                        // Temp database used, automatically backup with unique name (timestamp)
                        QString newName = QDateTime::currentDateTime().toString("yyMMdd-hhmmss");
            QString newPath = _preferencesDialog->getWorkingDirectory()+QDir::separator()+newName+".db";
            //QString newPath = "Salida.db";
            try{
            //newPath = QFileDialog::getSaveFileName(this, tr("Save database"), newPath, tr("RTAB-Map database files (*.db)"));
            //newPath = QFileDialog::getSaveFileName(this, tr("Save database"), newPath, tr("RTAB-Map database files (*.db)"));
                        if(newPath.isEmpty())
                        {
                                return false;
                        }

                        if(QFileInfo(newPath).suffix() == "")
                        {
                                newPath += ".db";
                        }

                        _newDatabasePathOutput = newPath;
            }catch(MyException& e){
                std::cout << "MyException caught" << std::endl;
                std::cout << e.what() << std::endl;
            }
                }
                else if(b != QMessageBox::Discard)
                {
                        return false;
                }
        }

        this->post(new RtabmapEventCmd(RtabmapEventCmd::kCmdClose, !_openedDatabasePath.isEmpty() || !_newDatabasePathOutput.isEmpty()));
        return true;
}

..........