Main.cpp + mainwindow.ui = ??

  • i just need to know,
    is it possible to ".show()" my work in .ui and .cpp files in 1 window??
    for example:
    #include "mainwindow.h"
    #include <QApplication>
    #include <QLabel>

    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    QLabel lbl("123");
    MainWindow w;;;

    return a.exec&#40;&#41;;

    (i added 2nd label in .UI file)

    1. can i display both of labels in 1 window?
    2. can i work (for exmpl, resize) 2nd lable by codding manually?

  • Moderators

    Yes, you just need to add your label to the layout in your MainWindow class. Just a couple of custom methods to expose the relevant layout (or clever reparenting :)) and it should work.

  • im newbie, so, ccan u write this lines?

    is it somthing like this?:

  • Moderators

    There are many ways. One would be:

    But I don't exactly know what the result would be. What I would do instead is to add method to your MainWIndow class that would expose one of the QLayout instances you have in the .ui and then add your label there. Sorry I won't write the code right now, it's 2 am in here now, I'm a tad too tired :D

  • ty
    it's works ok.

    1. @ lbl.setParent(w.centralWidget());@
    2. after closing program error "Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly"
    3. is it possible to siglnal /slot this 2 widgets?

Log in to reply