Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [solved] 0xC0000005 - try to use button (MSV 2010, Qt 4.8.2, W7)
Forum Updated to NodeBB v4.3 + New Features

[solved] 0xC0000005 - try to use button (MSV 2010, Qt 4.8.2, W7)

Scheduled Pinned Locked Moved Installation and Deployment
9 Posts 4 Posters 4.7k 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.
  • G Offline
    G Offline
    Grybb
    wrote on last edited by
    #1

    I created window in Qt Designer
    !http://chrn.wz.cz/QTerr.png(Qt Designer - picture)!
    Everything works fine (I can compile it and it seems Ok) but when I do any action with button during compilation is occur this error:

    bq. Unhandled exception at 0x66a1d4c1 (QtCored4.dll) in Database_normalizator.exe: 0xC0000005: Access violation reading location 0x00000025.

    my mainwindow.h:

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QtGui/QMainWindow>
    #include "ui_mainwindow.h"
    #include "AddAttDialog.h"

    class MainWindow : public QMainWindow, public Ui::MainWindow
    {
    Q_OBJECT

    public:
    MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~MainWindow();

    public:
    Ui::MainWindow ui;

    public slots:
    void addAttribute();
    };

    #endif // MAINWINDOW_H@

    my mainwindow.cpp:

    @#include "mainwindow.h"

    MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
    {
    ui.setupUi(this);

    (*addAttPushButton).setText("hhh"); //!!!error!!!
    (*editAttPushButton).hide(); //!!!error!!!
    connect(addAttPushButton, SIGNAL(clicked()), //!!!error!!!
    this, SLOT(addAttribute()));
    }

    void MainWindow::addAttribute()
    {
    /AddAttDialog dialog(this);
    if (dialog.exec())
    QString str = dialog.lineEdit->text();
    /
    }

    MainWindow::~MainWindow()
    {

    }@

    If I don´t use "!!!error!!! lines application behaves correctly...

    1 Reply Last reply
    0
    • W Offline
      W Offline
      Wilk
      wrote on last edited by
      #2

      Hello.
      Did you try using -> here
      @(*addAttPushButton).setText("hhh"); //!!!error!!!@
      instead of dereferencing pointers?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        @
        (*addAttPushButton).setText("hhh"); //!!!error!!!
        (*editAttPushButton).hide(); //!!!error!!!
        connect(addAttPushButton, SIGNAL(clicked()), //!!!error!!!
        this, SLOT(addAttribute()));
        @

        Are you sure that those pointer are pointing anywhere?
        It would not be compliant at least with older versions of designer.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • ZlatomirZ Offline
          ZlatomirZ Offline
          Zlatomir
          wrote on last edited by
          #4

          You need something like this:
          @
          MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
          : QMainWindow(parent, flags)
          {
          ui.setupUi(this);

          ui.addAttPushButton->setText("hhh"); //!!!error!!!
          ui.editAttPushButton->hide(); //!!!error!!!
          connect(ui.addAttPushButton, SIGNAL(clicked()), //!!!error!!!
          this, SLOT(addAttribute()));
          }
          @
          PS: since addAttPushButton isn't declared in Mainwindow class, i guess that addAttPushButton is part of the ui object (you created it in the Designer)

          https://forum.qt.io/category/41/romanian

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Grybb
            wrote on last edited by
            #5

            Wilk: It was the same.

            koahnig: Yes, they do.

            Zlatomir: Thank you, you´re right it is working. I didn´t know that I have to use ui. prefix. In some project (which is not mine) it is without ui. and everything else is the same (or at least it seems to be to me).

            1 Reply Last reply
            0
            • ZlatomirZ Offline
              ZlatomirZ Offline
              Zlatomir
              wrote on last edited by
              #6

              ui is not a "prefix" it's an instance (in your case) or a pointer to an instance of a class that uic is generating from the xml file that you create using Qt Designer.
              You have that ui object in your class:
              @
              class MainWindow : public QMainWindow //***you don't need to derive from this second class if you use an instance - that ui object
              //, public Ui::MainWindow
              public:
              Ui::MainWindow ui;@

              Learn more about using designer file into C++ code "here":http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html

              ***i wanted to ask how your code compiled, because it shouldn't, but now i saw - please read the documentation page i linked ;)

              //you can mark the topic as solved by edit the first post and add [solved] at the beginning of the title and also you might want to learn more about C++ (i might be wrong, but from that "prefix" i deduced you are not familiar with C++), two free books can be found with a search for Thinking in C++ - there are two very good C++ volumes written by Bruce Eckel - and are also available as free download.

              https://forum.qt.io/category/41/romanian

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Grybb
                wrote on last edited by
                #7

                It compiled Ok (actually now I have another error probably becouse of the same). I will look at your link - thank you.

                1 Reply Last reply
                0
                • ZlatomirZ Offline
                  ZlatomirZ Offline
                  Zlatomir
                  wrote on last edited by
                  #8

                  It compiled ok because you had those member pointers both in your class and in the ui object (i didn't saw the second class you inherited until i copied the code to show you what is that ui), so you shouldn't use two methods to include the uic generated code, choose only one method.

                  And the crash was happening because the member pointers (the ones that you tried to use) were uninitialized.

                  https://forum.qt.io/category/41/romanian

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    Grybb
                    wrote on last edited by
                    #9

                    Now I finally read the link and it is clear to me where was the error. Nice to know it. :-)

                    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