Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Dereferencing not NULL pointer crashes
Forum Updated to NodeBB v4.3 + New Features

Dereferencing not NULL pointer crashes

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 1.6k Views 1 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.
  • W Offline
    W Offline
    Whatever123
    wrote on last edited by
    #1

    Hello

    I have a QDialog with a public member function "toFront".
    QDialog has a private member attribute m_db of type (QsqLDatabase *).

    Calling
    @qDebug() << "front " << m_db << " " << *m_db;
    @

    in the constructor works fine. Output is:
    @form 0x7fff5fbffa80
    form QSqlDatabase(driver=""QSQLITE"", database=""/Users/christoph/qt_projects/teiledb/teileDatenbank_playground.sqlite"", host="""", port=-1, user="""", open=true)@

    Doing the same in the member function "toFront" leads to a crash when dereferencing the pointer. The adress is the same like above (first line).
    @qDebug() << "form " << m_db ; // ok
    qDebug() << "form " << *m_db ; // crash
    @

    Crash means programm is not responding, no error whatsoever visible.

    QDialog (instance m_formAddCatLoc) itself is a member of MainWindow. QDialogs member function "toFront" is called from MainWindow
    @void MainWindow::addCatReleased(){
    m_formAddCatLoc->toFront(FormAddCatLoc::ADD_CATEGORY);
    }
    @

    addCatReleased is a SLOT called when a button goes up
    @connect( ui->pb_addCat, SIGNAL(released()), this, SLOT(addCatReleased()));
    @

    Am I missing a basic qt/thread/scope problem?? Looks like a memory protection for me ... but why?

    Regards
    Christoph

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      How do you allocate m_db?
      Could you show a constructor and toFront source code?

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Whatever123
        wrote on last edited by
        #3

        [quote author="andreyc" date="1418996164"]How do you allocate m_db?[/quote]
        Ohhhh .... I found my problem.
        QSqlDatabase is a local vaiable of the constructor so it's allocated on the stack and deleted after constructor is done.

        It did not come to me since in every other case I access the Database throug a QSqlTableModel, however that's a copy and not a reference to my database.

        Thanks anyway :)

        1 Reply Last reply
        0

        • Login

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