SIGSEV error on setDatabaseName



  • Hi,
    I have the following code:

       QSqlDatabase db = QSqlDatabase::addDatabase ("QSQLITE");
    //   db.setDatabaseName ("C:/Programming/Projects/FolkFriends/db.db");
       db.setDatabaseName (fileQstring);
    

    If I run the second line it runs correctly. if I run the third line it gives a SIGSEGV error.

    in the .h file:

    QString fileQstring = ("C:/Programming/Projects/FolkFriends/db.db");
    

    Please help me to figure out why I get this error message. Thank you.


  • Moderators

    Why did you put the string in (...)?
    Where does it crash? I mean did you try to debug your program to see where it crashes?



  • @jsulm I tried to debug and this line seemed to be the problem.


  • Qt Champions 2016

    @gabor53
    SIGSEGV is a segmentation fault, which basically means you have a corrupted memory somewhere. You should track it down through the debugger. Could you provide a stack trace of the crash?



  • Can you please tell me how to do that? I' m still trying to figure out how the debugger works.


  • Qt Champions 2016

    @gabor53
    Stack trace
    This is the current stack in Qt creator. So when the crash occurs you'd right click it and choose "copy contents"/"extract" or something of that sort. Paste it somewhere online (for example codepaste.net) and post the link here.



  • @kshegunov
    There is nothing in the Stack.


  • Qt Champions 2016

    @gabor53
    Are you sure you're looking at the stack window, there are other debugger windows as well? If you don't have a stack while debugging, then that means you're not running the program through the debugger ... Can you set breakpoints and does the program stop at those?



  • @kshegunov
    I use ->Debug -> Start Debugging -> Start Debugging (F5). How else can I run to see something in stack?



  • I have the following in the Debug log:

    <95python theDumper.stackListFrames({"limit":20,"options":"",})

    &"python theDumper.stackListFrames({"limit":20,"options":"",})\n"
    &"Traceback (most recent call last):\n"
    &" File "<string>", line 1, in <module>\n"
    &"AttributeError: Dumper instance has no attribute 'stackListFrames'\n"
    &"Error while executing Python code.\n"
    95^error,msg="Error while executing Python code."


  • Qt Champions 2016

    @gabor53

    I use ->Debug -> Start Debugging -> Start Debugging (F5). How else can I run to see something in stack?

    No, you're doing it correctly.

    &"AttributeError: Dumper instance has no attribute 'stackListFrames'\n"
    &"Error while executing Python code.\n"

    This however leads me to believe there's something wrong with the debugger, or rather the debugger wrapper. What OS, Qt Creator version and debugger are you using?



  • @kshegunov
    I use Windows 10, Qt 5.6, Debugger: GNU gdb 7.8 for MinGW 4.9.2 32 bit and I use MinGW 4.9.2 32 bit compiler.


  • Qt Champions 2016

    @gabor53

    Okay, it should work. Are you building in debug mode? Can you paste (somewhere online) the compile lines and/or linker line from building as well?



  • @kshegunov
    Yes, I'm building in debug mode.

    Is this what you needed?

    configure -static -platform win32-g++ -prefix "C:\Qt\Qt5.4.0_Static" -release -opensource -confirm-license -nomake examples -nomake tests -nomake tools -opengl desktop -no-angle -qt-sql-sqlite -make libs -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype



  • @kshegunov
    I finally managed to get the stack. Here is the link to it:
    stack
    I installed the latest update and it made debug work better.


  • Qt Champions 2016

    @gabor53

    I finally managed to get the stack.

    Great!

    Here is the link to it

    Yes, that is superb. See the top of the stack (the reason I requested it in the first place):

    1  QBasicAtomicOps<4>::ref<int>                                     qatomic_x86.h                  181  0x6b9cebc8 
    2  QBasicAtomicInteger<int>::ref                                    qbasicatomic.h                 129  0x6b9e1070 
    3  QtPrivate::RefCount::ref                                         qrefcount.h                    55   0x6ba534a7 
    4  QString::operator=                                               qstring.cpp                    1739 0x6b7f67d3 
    5  QFile::QFile                                                     qfile.cpp                      255  0x6b85cdb4 
    6  Additem::FunctAddtoDb                                            additem.cpp                    57   0x40453b
    

    This is what functions were entered at the point where the crash occurred. Notice there's no mention of QSqlDatabase at all. :)

    So, my next question would be, what do you have in additem.cpp at line 57 (this would be called from your review::on_submit_Button_clicked slot at line 96). There's a QFile instance creation that crashes (or rather its constructor argument causes the crash).



  • @kshegunov

    Line 57 is

    QFile file(fileName);
    

    File name is defined in an other function:

    QString Additem::findimage()
    {
        Image_Button->setStyleSheet ("QPushButton{"
                                     "background-color:rgb(0, 255,0);"
                                     "border-style: outset;"
                                     "border-width: 2px;"
                                     "border-radius: 10px;"
                                     "border-color: beige;"
                                     "font: bold 14px;"
                                     "min-width: 10em;"
                                     "padding: 6px;}"
                                     );
    
        QString sPath = "C:/";
    
        QFileDialog *fileDialog = new QFileDialog;
    
        fileName = fileDialog->getOpenFileName(this,
                      tr("Finding Friend's Image"),sPath, tr("Image Files (*.png *.jpg *.bmp)"));
    
    
        display_Label->setFixedSize (100,100);
    
           if(fileName=="")
               {
                   qDebug() << "No image was chosen.";
                   QMessageBox::warning (this,"Error 1002","No image was choosen!");
               }
               else
               {
                  qDebug() << "Image was chosen!";
    
                  QPixmap pix(fileName);
    
                  int w = display_Label->width ();
                  int h = display_Label->height ();
                  display_Label->setPixmap (pix.scaled(w,h,Qt::KeepAspectRatio));
    
                  grid->addWidget (display_Label,2,2,3,1,Qt::AlignLeft);
    
           }
    
           return fileName;
    }
    

  • Qt Champions 2016

    @gabor53 said:

    Line 57 is
    QFile file(fileName);

    Then indeed, this is somehow the reason for the crash. You should investigate with the debugger what exactly causes it. Stop it before the object is created, see what the file name variable contains. Perhaps check if everything is fine with how you create it or assign its value.



  • @kshegunov
    Finally I figured out that the problem is the missing

    QSqlDatabase::removeDatabase ();
    

    after

    db.close();
    

    Thank you for your help!!!


Log in to reply
 

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