Call a dialogbox crash...



  • i have two differents dialogbox called from menu actions: "open project" and "new project".
    each dialogbox called by ->exec() open well.
    in each of these "new_project" and "open_project", there is a buton named "new location", who call the same dialogbox "new_location".

    In the dialogbox "new_project", the pushbutton slot make the "new_location" dialogbox open perfectly.
    in the dialogbox "open_project", the pushbutton slot make the "new_location" dialobox not open and crash the application.

    here is the pat of code (same in the two open_project and new_project dialog box) for call the new_location:

    @
    void open_project::on_pushButton_new_location_clicked() {
    dialog_new_location = new new_location(this);
    dialog_new_location->exec();
    locations_refresh();
    }
    @

    here the definition of the "private slots" and "private" pointer: (same in new_poject.h and open_project.h):
    @
    private slots:
    void on_pushButton_new_location_clicked();
    private:
    new_location *dialog_new_location;
    @

    i can not understand why the application crash when i call the dialogbox "new_location" from open_project and open well when i call it from "new_project". The code for define and call it is exactly the same.

    i forget something or this is a strange Qt bug ?

    any idea ?



  • Hi,

    The amount of code you have provided is not enough for me to reason about what is going on there.

    Looking at what you have provided, I see that you create a new instance of the new_location dialog every time a button is clicked. These objects won't get deleted until you close your application. Why don't you instantiate the object on the stack so that it gets cleaned up when the function returns?
    @
    void open_project::on_pushButton_new_location_clicked() {
    new_location nl;
    nl.exec();
    locations_refresh();
    }

    @



  • i try what you tell me...
    but in fact, this is exaclty the same effect.

    from my new_structure the call works

    from my open_project, the call crash the application

    Also... yes, what you tell me around i creat ea new instance is right.
    It is a better way to just create it at last time and all delete at the end of the function call.

    But this not resolve the problem.

    I really have no idea of why this dialogbox open well from new_structure and not from open_project. The call is exactly the same also open_project and new_structure are QDialogBox together, with same type of class. what i can give more for someone could try to help ?
    what can make a similare call crash from one caller and not from an other one ?



  • If the code is the same

    Doesn't the debugger tell you on what line in the code it crashed?
    Does the locations_refresh() function accesses the dialog_new_location member? If so, than my suggestion about how to change that slot is not valid anymore.
    Could you also post here the corresponding slot in the new_project class?
    Couldn't you provide a running example project so that I can see the crash myself?



  • i have no debugger configured. But yes, i have to now use a debugger.
    so i have to learn how to config it and use it with QtCreator.

    the location_refresh() is a function inside the caller (open_project) who never try to go inside the dialog who has to open by the call. Also, if i comment this line, the application crash same.

    the two slot (locations_refresh) isnide new_project and inside open_project and inside new_structure are exactly the same, and serve to refresh a treView.

    here is the code of this function:
    @
    //replace newproject by new_structure or open_project depend of the class...
    void newproject::locations_refresh() {
    if(!store_DB_locations.isEmpty()) {
    store_DB_locations.clear();
    locations_name->clear(); }
    QSqlQuery query;
    query.prepare("SELECT name, id, id_parent FROM "Locations""
    "ORDER by (id_parent, name) ASC;");
    user->execDB(query);
    while(query.next())
    store_DB_locations[query.value(2).toInt()].
    insert(query.value(1).toInt(),
    query.value(0).toString());
    QStandardItem *rootNode = locations_name->invisibleRootItem();
    find_Childs(0, rootNode);
    ui_newproject->treeView_locations->setModel(locations_name);
    ui_newproject->treeView_locations->setHeaderHidden(true);
    ui_newproject->treeView_locations->setColumnHidden(1,true);
    }
    @



  • When you open a new project with Qt Creator, it asks you to define a Debug and a Release configuration for your project. Also Qt Creator is quite good at detecting the debuggers installed on a system. If your project doesn't contain a Debug build configuration, you can add a new build configuration in Projects view and set the qmake build configuration to Debug under Build Steps > qmake in Projects view.

    I am quite surprised but also impressed that you came this far without using a debugger.



  • my technic (because i'm a beginer) is to use a wall panel board in front of my desk and some white paper for have a clear view (has i can have) of the construction of my code. Also, i try to follow some exemples i read on internet for learn in the same time. But lot of time for reflexions before action. Also, i need it because of 23 .cpp files existing allready (models, implementation, special class, with a login/users system and use of postgresql database with now 25 tables... ).

    I think debugger could make me win time maybe for strange thinks i can not understand (lake of knowledge for sure).

    So yes, i was just reading around how to use the debugger. my debugger under linux is GDB.
    i would try it again tomorrow and will tell you more if you want (now it is late for me... 19H10) and i have to go eating.

    thanks for try to help, and i will follow your recommendation and do the debugger operational for work.



  • ok, the debugger setup make it run (but i need to downgrade gdb because QtCreator can not use gdb-7.8 for show content of variables...).
    and then i can see that the problem is from lib/sqldrivers/libqsqlpsql.so

    the problem occur when (in the same time):
    #i have a QSqlQueryModel setQuery(myquery) who set a model for a listview and some widget form
    #i have on the same database instance call some other QSqlQuery call
    #i open an other one dialogbox who use same database connection instance and use QSqlQuery.

    the problem of use same instance connection with different QSqlQuery is not a problem.... because i do it and populate the model after (and not directly by a SQLQt model...), but if i use a Qt QsqlModel... this is a problem. Qt can not do it, it seems to be a limitation of Qt self code.
    I hope that call an other one instance for connect to the database would resolve the problem. If not... it would not be possible to use in a real application more big than a little, a QSqlModel tool from Qt.

    sniff...



  • no... i use an other one database call totaly independant from the other one in the dialog caller, but this application crash same.

    so... Andre, you tell me that call a dialogbox by .exec() coudl make problem (and so... that it is a bad practice), could you give me, please, an exemple of code for use .open() instead of the exemple from the Qt documentation ?

    the way this app crash from one caller and not from an other one (same technic of call) is really strange. And no one here seems to have an idea about what could be, except the only one comment from Andre who tell that .exec() call of dialogBox could occur problems.

    so... Andre, i trust you...


Log in to reply
 

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