Access to Object / various errors



  • Hi,

    I have created a fairly easy demonstration project to investigate a much bigger project I am working at. So there are some unused fields and so on, but I think that should be no harm for the technical issues I have with it.

    Funnily, there are various errors, I have quite some trouble to describe the different states. My first approach would be to confirm, that someone else has problems as well and its not in my installation or something.

    I have only 5 files:
    main.cpp
    mainwindow.h and .cpp
    state.h and .cpp

    main.cpp:

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    
    

    mainwindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <state.h>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
        state windowState;
    };
    
    #endif // MAINWINDOW_H
    

    mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        windowState.append( 0x73 );
        windowState.data.append( 0x74 );
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    state.h:

    #ifndef STATE_H
    #define STATE_H
    
    #include <QString>
    #include <QByteArray>
    
    class state
    {
    public:
        state();
    
        void append( char appData );
    
        QByteArray data;
        int dummy; // try to delete this
        QString errorString; // next, try to push this to be before the QByteArray
    };
    
    #endif // STATE_H
    

    state.cpp:

    #include "state.h"
    
    state::state() {}
    
    void state::append(char appData){
        data.append( appData );
    }
    

    It doesn't really do anything, all it does for me is crushing. Can somebody confirm this or is it only for me?

    Next, there are three things I have done to make the whole even more interesting. In state.h change:

    1. Remove the "int dummy;" field
    2. Replace the "QString errorString;" to be before the QByteArray
    3. Remove the "QString errorString;" at all

    I would be more than interested in finding how this behaves for you?

    Thanks a lot,
    Stephan


  • Qt Champions 2016

    Hi
    First I just ran it.
    Then tried to both delete the dummy and move the QString.
    No crashes.

    https://www.dropbox.com/s/yts645v45n0ugnl/Testcrash.zip?dl=0
    In case others want to try.


  • Moderators

    Where does it crash?



  • Hi mrjj, sorry, I could have packed the project myself and saved you that part of work, didn't think of it... On the other hand, it gave me some conclusions...

    Even it seems not logical, I downloaded your project, it looks pretty much exactly like mine, but yours didn't crush while mine still does / did. So I looked for differences, obviously. The only difference - besides the name of the project - was the build path which, in my project, was configured to be within the projects directory. Pushed that to the parent, now it works fine... Never thought this could be a reason for the errors I received...

    Thanks!
    Stephan


  • Qt Champions 2016

    @StephanWoebbeking
    Ok. that is good news even I do wonder
    why.
    There must been something old in the last
    build folder. (which was now rebuild)
    But my Imagination fails to understand how
    it could have made u crash.



  • Hi jsulm,

    well, I received a "application terminated in an unusual way" error without any location. After removing the "int dummy" I received a segmentation fault within the generated ui code.

    I "invented" this to reproduce the segmentation fault errors we have already discussed in another thread. Now, I was successfully reproducing it as it looked pretty much similar. But for my real project, the build directory is NOT in the project directory, so I still don't know what to do...

    But what I found already is, that my initial error (from the other thread) can be solved but switching the variable definition before all other variables... I am somehow lost here...

    Best Regards,
    Stephan


  • Qt Champions 2016

    Hi
    it does sounds like moc generate
    something in your ui_mainwindow
    that makes you crash.

    I was wondering:

    If u look in old location for build (for mini sample)
    where is still crashes and look at the ui_ file
    and then compare new build folder where it doesn't crash.

    Are they the same ?



  • Hi, there is no ui_mainwindow file in the directory? Actually I have changed my folder structure now; it wasn't really my intention to place it into the project directory, so I corrected this and since then I am not able to reproduce the error I had.

    Well, that's good news from one point, but the bad point is that I wanted to reproduce an error from my big project and now I don't know any more, what else to put into the small project to get the error...

    Stephan


  • Qt Champions 2016

    Well if you cannot reproduce the error in small project then
    it must have been some odd stuff and not actually the code.

    If you can reproduce in big project then maybe look at other areas then the code
    in small project.

    Sadly we cannot really help as its near impossible to give advice to as it can be anything.


Log in to reply
 

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