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

Missing (#include) "ui_device.h" ?



  • One of the examples I am trying to utilize includes "ui_device.h"
    Even Linux "find" (Ubuntu 16 ) cannot locate such file.
    What am I doing wrong?


  • Lifetime Qt Champion

    Hi,

    You didn't build the example yet. That header is generated by uic based on the FORMS entry in the .pro file of the project.



  • @AnneRanch what if you try following an introductory tutorial to Qt?



  • OK, from the other post - I need to keep C++ code , main - "synchronized" with project file manually.
    So using "application" example as "template" is really not that good idea.
    Probably better off by building the "new" project from scratch.
    I just copied the "bluetooth project" to my "application" and will have some duplicated entries to deal with.
    Again - going back to other post - when I get all the entries into project file I should be able to see compiler build the "ui-xxx .h" files, right ?
    Actually - creating / building header files by compiler seems as another anomaly of Qt - should that be some kind of (static) library instead?


  • Qt Champions 2019

    @AnneRanch It's not the compiler who generates the files, it's the uic tool which is part of Qt toolchain.
    Generating code isn't that unusual actually and is for sure not an anomaly. This can help to move all the boring boiler plate code to such tools.
    Short explanation: *.ui files generated by Qt Designer are XML files. To be able to use them in C++ efficiently you need to translate them into C++ code. Do you want to do this manually? I guess not, so that's why there is this uic tool - it translates XML from Designer into C++ code which then is compiled as any other C++ code.



  • @Pablo-J-Rogina
    I really cannot , since I started by using "application" example where most of this is already buidl - assuming by qmake.
    I'll do my next project from scratch - as "new" - and then I can follow the script.
    Thanks for suggesting that,

    .

    @jsulm said in Missing (#include) "ui_device.h" ?:

    @AnneRanch It's not the compiler who generates the files, it's the uic tool which is part of Qt toolchain.
    Generating code isn't that unusual actually and is for sure not an anomaly. This can help to move all the boring boiler plate code to such tools.
    Short explanation: *.ui files generated by Qt Designer are XML files. To be able to use them in C++ efficiently you need to translate them into C++ code. Do you want to do this manually? I guess not, so that's why there is this uic tool - it translates XML from Designer into C++ code which then is compiled as any other C++ code.

    I hope this will post as reply to the above.

    IMHO complier "generates code" , I have never seen machine generated C style header file. I am not being picky - just trying to understand "Qt" terminology.

    As far as I can tell my initial mistake was expecting the Qt Creator to be IDE.
    (Staring with canned "application" example the way I did was not that smart either. )
    Plain C++ text editor to be precise.

    Now I am learning that it is simply not so.
    It is a complex of tools and for a new user little overwhelming to navigate.

    For instance - what is "Qt Designer"?

    I have a hard time to call "Qt creator" "IDE" if I have to exit it to rename project. I have a bad habit to make duplicates of my "under construction" project and so far have not tried to do so within "Qt creator".

    But I am sure with the help of this forum , which I greatly appreciate , it will eventually fly as expected.



  • @AnneRanch said in Missing (#include) "ui_device.h" ?:

    @Pablo-J-Rogina
    I really cannot , since I started by using "application" example where most of this is already buidl - assuming by qmake.
    I'll do my next project from scratch - as "new" - and then I can follow the script.
    Thanks for suggesting that,

    .

    @jsulm said in Missing (#include) "ui_device.h" ?:

    @AnneRanch It's not the compiler who generates the files, it's the uic tool which is part of Qt toolchain.
    Generating code isn't that unusual actually and is for sure not an anomaly. This can help to move all the boring boiler plate code to such tools.
    Short explanation: *.ui files generated by Qt Designer are XML files. To be able to use them in C++ efficiently you need to translate them into C++ code. Do you want to do this manually? I guess not, so that's why there is this uic tool - it translates XML from Designer into C++ code which then is compiled as any other C++ code.

    I hope this will post as reply to the above.

    IMHO complier "generates code" , I have never seen machine generated C style header file. I am not being picky - just trying to understand "Qt" terminology.

    As far as I can tell my initial mistake was expecting the Qt Creator to be IDE.
    (Staring with canned "application" example the way I did was not that smart either. )
    Plain C++ text editor to be precise.

    Now I am learning that it is simply not so.
    It is a complex of tools and for a new user little overwhelming to navigate.

    For instance - what is "Qt Designer"?

    I have a hard time to call "Qt creator" "IDE" if I have to exit it to rename project. I have a bad habit to make duplicates of my "under construction" project and so far have not tried to do so within "Qt creator".

    But I am sure with the help of this forum , which I greatly appreciate , it will eventually fly as expected.

    OK,
    found how to edit the widgets.

    But, another snag / confusion

    My original post was about missing ui_device.h AKA header file.
    I have copied the device.h file which includes this "ui_device.h".
    I have manually added "device.ui" to project , under "forms" .
    With exceptions of other , yet undefined references errors , my project complies.
    Now I have (additional) questions:
    do I have to add the x.ui "form" into project manually by editing project file ?
    is this naming convention - putting "ui-" in front of the include file name described somewhere?
    I can edit / access multiple projects so is there a way to directly "copy" these ui header files from one project to another? I ended up coping them outside Qt IDE.


  • Lifetime Qt Champion

    Hi,

    The format and its use are explained in the Qt Designer Manual.


  • Moderators

    Code generators are not something uncommon. I've used a lot of them over the years and written a couple of them on my own. They are basically producing boilerplate, something you could do by hand but would be tedious and took long. To be clear - you can use Qt without them but it's just not something anyone does because of the amount of code to write by hand if you opt-out of them.

    Qt uses them in 3 key areas:

    • the uic (UI Compiler) tool reads XML based designer files XXX.ui and generates ui_XXX.h C++ headers from them
    • the moc (Meta Object Compiler) used for generating class reflection code, reads C++ header XXX.h containing QObject derived class declaration and generates moc_XXX.cpp file implementing various aspects of the meta-object system.
    • the rcc (Resource Compiler) takes XML based XXX.qrc files containing list of resource files and generates qrc_XXX.cpp files containing stringized versions of these resources as a C++ arrays of bytes.

    As to what particular Qt XXX things are:
    Qt - the C++ library consisting of various C++ libraries (or modules, whatever name you prefer) like QtCore, QtWidgets etc.
    Qt Designer - a standalone visual designer application that helps you create UIs in a XML formal files XXX.ui, used by uic
    qmake - a build tool like CMake or MSBuild, takes XXX.pro project file and invokes compiler, linker and other toolchain tools on the files following the rules from the .pro file
    Qt Creator - an IDE like Visual Studio, XCode, KDevelop etc., can be used to edit qmake (or other) based projects, has integrated version of Qt Designer and specialized support for Qt library

    As far as I can tell my initial mistake was expecting the Qt Creator to be IDE.

    It is. It lets you edit projects, code, configure tooltchains, debug, connect to remote devices, manage source control and bunch of other features... it's pretty well featured actually.

    I have a hard time to call "Qt creator" "IDE" if I have to exit it to rename project.

    Granted, but to be honest renaming a project is not something you do very often. It has loads and loads of other features far more useful than that.

    do I have to add the x.ui "form" into project manually by editing project file ?

    If you're adding a new .ui file there's a wizard. For existing files you can either manually edit the .pro file or use the "Add existing files" option from the context menu on the .pro file. It was very weird for me to edit the .pro file manually at first when I switched from Visual Studio, but now that I know the actual syntax I find it a lot more convenient this way. Faster than through wizards and dialog windows.

    is this naming convention - putting "ui-" in front of the include file name described somewhere?

    If you use it from command line the uic generator can name the file anything (it takes that as a parameter) but the ui_ prefix is just a convention that has settled over the years and that's what qmake projects name it. I don't think it is documented other than by an example here.

    I can edit / access multiple projects so is there a way to directly "copy" these ui header files from one project to another?

    Not that I know of. Qt Creator does not have a lot of file explorer features. If you copy them a lot wouldn't it make more sense to have just one and use it from multiple projects?



  • @Chris-Kawa said in Missing (#include) "ui_device.h" ?:

    Code generators are not something uncommon. I've used a lot of them over the years and written a couple of them on my own. They are basically producing boilerplate, something you could do by hand but would be tedious and took long. To be clear - you can use Qt without them but it's just not something anyone does because of the amount of code to write by hand if you opt-out of them.

    Qt uses them in 3 key areas:

    • the uic (UI Compiler) tool reads XML based designer files XXX.ui and generates ui_XXX.h C++ headers from them
    • the moc (Meta Oobject Compiler) used for generating class reflection code, reads C++ header XXX.h containing QObject derived class declaration and generates moc_XXX.cpp file implementing various aspects of the meta-object system.
    • the rcc (Resource Compiler) takes XML based XXX.qrc files containing list of resource files and generates qrc_XXX.cpp files containing stringized versions of these resources as a C++ arrays of bytes.

    As to what particular Qt XXX things are:
    Qt - the C++ library consisting of various C++ libraries (or modules, whatever name you prefer) like QtCore, QtWidgets etc.
    Qt Designer - a standalone visual designer application that helps you create UIs in a XML formal files XXX.ui, used by uic
    qmake - a build tool like CMake or MSBuild, takes XXX.pro project file and invokes compiler, linker and other toolchain tools on the files following the rules from the .pro file
    Qt Creator - an IDE like Visual Studio, XCode, KDevelop etc., can be used to edit qmake (or other) based projects, has integrated version of Qt Designer and specialized support for Qt library

    As far as I can tell my initial mistake was expecting the Qt Creator to be IDE.

    It is. It lets you edit projects, code, configure tooltchains, debug, connect to remote devices, manage source control and bunch of other features... it's pretty well featured actually.

    I have a hard time to call "Qt creator" "IDE" if I have to exit it to rename project.

    Granted, but to be honest renaming a project is not something you do very often. It has loads and loads of other features far more useful than that.

    do I have to add the x.ui "form" into project manually by editing project file ?

    If you're adding a new .ui file there's a wizard. For existing files you can either manually edit the .pro file or use the "Add existing files" option from the context menu on the .pro file. It was very weird for me to edit the .pro file manually at first when I switched from Visual Studio, but now that I know the actual syntax I find it a lot more convenient this way. Faster than through wizards and dialog windows.

    is this naming convention - putting "ui-" in front of the include file name described somewhere?

    If you use it from command line the uic generator can name the file anything (it takes that as a parameter) but the ui_ prefix is just a convention that has settled over the years and that's what qmake projects name it. I don't think it is documented other than by an example here.

    I can edit / access multiple projects so is there a way to directly "copy" these ui header files from one project to another?

    Not that I know of. Qt Creator does not have a lot of file explorer features. If you copy them a lot wouldn't it make more sense to have just one and use it from multiple projects?

    I hope is OK to use quote.
    I appreciate all your comments, it is helping me a lot.

    I understand the limitations of Qt IDE , I guess I got spoiled by ability of the other IDE as far as copying files between projects.

    I'll take a look on using "subpoject", maybe that is the ticket.

    Perhaps there is an official way to do "version control" within IDE.

    As far as using commend line for "UIC" I 'll stick with GUI for now.


  • Qt Champions 2019

    @AnneRanch said in Missing (#include) "ui_device.h" ?:

    Perhaps there is an official way to do "version control" within IDE.

    You can use several version control tools with QtCreator, like Git, Subversion, Mercurial and CVS.


Log in to reply