Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

changing objectName in design view does not update names in mainwindow.cpp



  • I recently started learning Qt using the book Computer Vision With Qt 5 and OpenCV 3. I am also newish to C++ after having left it for C# and Python.
    I am having issues with changing the objectNames. I changed the name in Design view but when I access it in the mainwindow.cpp using ui-> , it does not show the new names in the intellisense/autocomplete.
    Concretely, I change lineEdit to inputLineEdit in design view and then try to use setText on ui->inputLineEdit->setText.
    the name inputLineEdit does not show up and instead shows lineEdit and lineEdit2 and all the other default names of the ui widgits.


  • Lifetime Qt Champion

    Hi and welcome to the forums
    try to delete the build folder and run qmake and rebuild all.
    ( you can find build folder in "Projects" (left side ) and simply right click the path and show it and delete it)
    alt text

    It sounds its stalling.
    Normally its renamed at once and a new ui_xxx file is generated.

    Also, you are using a .PRO file ?



  • Thanks for the response and sorry for the late reply.
    Yes, I am using a .pro file as well as a .pri file to include OpenCV.

    I agree about the stalling thing, it should have renamed it immediately. I have used Visual Studio in the past and it does this with its UI tools.

    Another interesting thing I found is, the names are the default ones in the ui_mainwindow.h file and changing them manually does not work.
    i.e. I still see lines like:
    lineEdit->setObjectName(QStringLiteral("lineEdit"));
    lineEdit_2->setObjectName(QStringLiteral("lineEdit_2"));
    and try to change it manually but the new names are still not recognized.


  • Lifetime Qt Champion

    @arif_sohaib
    hi
    Ok, could it be possible you have copied files around at some point
    and have 2 ui_mainwindow.h ?

    if you delete ui_mainwindow.h , is it generated again ?

    If you manually change the names in ui_mainwindow.h and its not changed back when you compile and
    its not seen in .cpp , it must be another one being linked to project or there is 2 of them or something like that.



  • I just made another project starting from scratch and it now works.
    Thanks for the help



  • I had run into one more problem that others looking at this thread might want a solution to.
    After building and running the program, I added a checkBox widgit and it was not showing up in code. This was the same thing as was happening before. I deleted the ui_mainwindow.h file and then it started working.
    So it looks like the problem was that qmake was not rebuilding the ui_mainwindow.h file after updates to the display unless its old version is deleted. I am not sure if this is the intended behavior or if it is my settings but if it is the normal behavior, this could turn a lot of people away from using Qt and needs to be fixed.


  • Lifetime Qt Champion

    @arif_sohaib
    Hi
    Its not normal at all.
    I use Designer all day and renaming anything is available at once
    via UI-> with no action on my part.

    Did you change/use shadow build folder or did anything special with the ui_xxx files ?

    Also check that you dont have a virus scanner blocking the files in the build folder.
    Especially if you are using Avast.


  • Lifetime Qt Champion

    @arif_sohaib,

    as @mrjj said, this usually works out of the box.

    one more idea: usually you don't open the generated ui_*.h files. if you do, you may be hit by a Clang bug that forbids updating the file.

    so if you have Clang Code Model enabled, you could check if it works if you don't open the generated files.



  • @mrjj said in changing objectName in design view does not update names in mainwindow.cpp:

    Did you change/use shadow build folder or did anything special with the ui_xxx files ?
    Also check that you dont have a vir

    I tried with both Shadow Build on and off. I also changed the build folder because under the default settings, it wasn't able to find the .exe file when I hit run so I changed it to "project folder/build" and it started working.
    As for virus scanner, I only have the default Windows Defender.



  • @aha_1980 said in changing objectName in design view does not update names in mainwindow.cpp:

    one more idea: usually you don't open the generated ui_*.h files. if you do, you may be hit by a Clang bug that forbids updating the file.

    I know not to touch generated files, and I don't for anything important, but I was just experimenting with getting it to work.
    I am not sure about Clang, I am not sure. I am using the Visual Studio 2017 15 C++ compiler. Most things that I didn't mention are on their default settings.
    And thanks for the reply.


  • Lifetime Qt Champion

    @arif_sohaib

    sorry for being so unspecific, I had QTCREATORBUG-15449 in mind.

    you can check with Help > About Plugins if Clang Code Model is enabled.

    Regards


  • Lifetime Qt Champion

    Hi
    That is very strange.
    if you manually delete the ui_ file and compile it works every time ?

    if you are using qmake, it normally call the UI tool correctly
    http://doc.qt.io/qt-5/uic.html

    Its just Creator + visual studio compiler and nothing special extra?



  • After the application compiled the first time alone with allowing adding more ui widgits, adding more widgits and compiling isn't causing any more problems.
    Now any ui elements I add immediately show up in the mainwindow.cpp file without any additional steps.


  • Lifetime Qt Champion

    @arif_sohaib
    Ok super. Not sure what was up with it :)


Log in to reply