Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to save the widgets load using UiLoader?
Forum Updated to NodeBB v4.3 + New Features

How to save the widgets load using UiLoader?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 203 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kattia
    wrote on last edited by Kattia
    #1

    Is it possible to save the widgets load using UiLoader into a ui variable like Ui::MainWindowClass *ui;?

    UiLoader loader;
    QFile file(":/file.ui");
    file.open(QIODevice::ReadOnly);
    
    QWidget* form = loader.load(&file);
    

    Currently i'm getting widget per widget like:

    QFrame* frame = form->findChild<QFrame*>("frame");
    QLabel* label = form->findChild<QLabel*>("label");
    

    How to save all widgets at once into a variable like Ui::MyClass *form;, in which then could be accessed like
    form_ui->frame , form_ui->label etc

    JonBJ 1 Reply Last reply
    0
    • K Kattia

      Is it possible to save the widgets load using UiLoader into a ui variable like Ui::MainWindowClass *ui;?

      UiLoader loader;
      QFile file(":/file.ui");
      file.open(QIODevice::ReadOnly);
      
      QWidget* form = loader.load(&file);
      

      Currently i'm getting widget per widget like:

      QFrame* frame = form->findChild<QFrame*>("frame");
      QLabel* label = form->findChild<QLabel*>("label");
      

      How to save all widgets at once into a variable like Ui::MyClass *form;, in which then could be accessed like
      form_ui->frame , form_ui->label etc

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Kattia
      C++ being a compiled language you cannot do this, you cannot create variables at runtime, depending on what is in a file. (Python could, but not C++.)

      To get variables at runtime that is why you run uic on the .ui file at build time. Which produces a ui_...h file defining the class for ui with individually named variables for each widget. No more findChild<>() calls. So why are you loading the .ui file via UiLoader::load() dynamically at runtime instead of letting it get processed via uic at compile-time?

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved