New Qt user - few questions



  • I'm new to Qt and used to a totally different IDE / API (visual studio and plain win32) and know starting with QtCreator 5

    As a plain winAPI programmer, many things here that should be easier are just more and more confusing to me, starting from :
    If I create a new qt Widget application project, it creates by default 4 files, 2 .cpp and the mainwindow.h / ui
    As I click the ui file and place widgets around, doesn't matter how much I run qmake or build the ui, the mainwindow.h and .cpp never changes, and I can't see any ui_mainwindow.h in any folder.
    I already saw that the .ui is defined as an XML file and thought that running qmake would have called the uic to compile the file and translate it to c++.

    Am I not supposed to see changes in those files ? If i'm using the designer to set SIGNALs and SLOTs of the widgets in the .ui how am I supposed to edit the implementations of the generated code ?

    How do I refer from the mainwindow.cpp to a button/combobox/anything created with the designer ?
    The book I'm reading (C++ gui programming with Qt 4-2ndedition) uses Qt4 and assumes I can read the generated c++ code from the designer and that I can change it, but that's not the case apparently



  • Hi, I also came from Visual Studio, if you spend some time with Qt Creator I think you will like it.

    In the design view, instead of doubleclicking as in Visual Studio you rightclick and select "Go To Slot.." choose Clicked() and you can edit inside the generated function just as in Visual Studio.

    Qt Creator normally doesn't show you the ui_mainwindow.h file (the one that mainwindow.cpp includes); one ways to see it: place the cursor on the #include line in mainwindow.cpp and press F2.
    To refer to your controls: uI_mainwindow.h gets included in Qt Creator's intellisense so just type ui-> and they should appear in the dropdrown.



  • Fortunately, the ui_mainwindow.h header isn't something you ever have to deal with directly (or at least only very, very rarely); though making it almost impossible to discover without grepping the filesystem is a bit awkward.

    The right-click/"Go to slot..." bit will jump you straight to the event handler method (neato) -- but make sure you are careful to give the elements of your program and UI meaningful names before you start jumping all over the place or making a lot of changes at once to an pre-existing interface (especially if its even a little complex). Some of the changes necessary in headers as you add elements to the UI take some experience to get used to.

    My first encounters with QtCreator were coming from a system programming environment where vim and emacs reign supreme and the languages are quite a bit different than C++. I found the best way to get my feet wet was to walk myself through a few of the Qt tutorials, starting with the elementary "build a QtWidgets app" IDE familiarization material and moving into the juicy parts of the Qt libraries I'd never seen before once I knew my way around. That was time well spent, and almost definitely paid for itself by shortening my period of introductory discomfort overall.



  • Hi,

    If you have created you UI project with Qt Creator than it is q qmake based project.

    Whenever you build your project after changing the UI in the Design mode, qmake will run uic, generate C++ code from the ui file. The generated code will be compiled and link into your application as well.

    You shouldn't manually edit generated _ui.h file because it will be regenerated from ui file during next build. But if you want to see its contents, just Ctrl + click it in mainwindow.cpp. It is #included there.

    To access the widgets you have put to UI in Design mode, you use the ui member function of your MainWindow class:
    @
    //for example
    ui->label->setText("...");
    @

    I suggest you go over the Qt Designer "manual":http://doc.qt.io/qt-5/qtdesigner-manual.html, which is available both as a stand-alone application with the name "Qt Designer" or as Design mode within Qt Creator.



  • You may find "these tutorials":https://www.youtube.com/playlist?list=PL2D1942A4688E9D63 useful.



  • If your just staring out, I suggest not even using Designer. When you start anew project within QtCreator uncheck the box for create UI file. The Widget names are pretty much self explainitory as are their methods. For me doing layouts has always been easier in a code editor then working with designer. Just my two cents


Log in to reply
 

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