[Solved] If want to copy, application crashes



  • Hello,

    I have a problem thats eventually easy for profis, but not for me. :(
    In my mainwindow there is an widget attribute (area), that contains an special textedit (class Editor inherits from QTextEdit). I want to call the copy method of Editor via action element in menubar of mainwindow.

    @
    void MainWindow::copy() {
    this -> area -> getEditor() -> copy();
    }
    @

    Here is my getter method for the editor attribute (that's private):

    @
    Editor *getEditor() { return editor; }
    @

    If I run my window and click on action element for copy, the application crashes. Debugger says this:
    "Stopped by Exception at 0x509b6bda, code: 0xc0000005; read access violation at: 0x0, flags=0x0 (first chance).
    I don't know, what I doing wrong. Please help me. :(



  • Use the debugger and find out if any of these is not what you expect:
    @void MainWindow::copy() {
    this;
    this->area;
    this->area->getEditor();
    this->area->getEditor()->copy();
    }@

    Go through it line by line and look where it crashes. Then you will know if an object is not initialized. The code you posted doesn't look fundamentally wrong, the error is probably created somewhere else.



  • Thank you for help! :)

    Search was successful! :)
    I created editor-variable local, not as global attribute. So the attribute was null of course. :D


Log in to reply
 

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