Note that there are some explanatory texts on larger screens.

plurals
  1. POQt: How does *.ui files and *.qss files get associated with MainWindow class instance?
    text
    copied!<p>It's still somewhat of a mystery. I used the stylesheet Qt example application, where it demonstrates usage of *.ui and *.qss files.</p> <p>They have a main window class which is designed in a *.ui. The code however contains no references at all to any *.ui or *.qss and yet they are associated at runtime. I can't understand how. </p> <p>this is the code to initialize the main window;</p> <pre><code>int main(int argc, char *argv[]) { Q_INIT_RESOURCE(stylesheet); QApplication app(argc, argv); MainWindow window; window.show(); return app.exec(); } </code></pre> <p>This is the code for mainwindow...</p> <p>*.h:</p> <pre><code>#ifndef MAINWINDOW_H #define MAINWINDOW_H #include &lt;QtGui&gt; #include "ui_mainwindow.h" class StyleSheetEditor; class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(); private slots: void on_editStyleAction_triggered(); void on_aboutAction_triggered(); private: StyleSheetEditor *styleSheetEditor; Ui::MainWindow ui; }; #endif </code></pre> <p>*.cpp:</p> <pre><code>include &lt;QtGui&gt; #include "mainwindow.h" #include "stylesheeteditor.h" MainWindow::MainWindow() { ui.setupUi(this); ui.nameLabel-&gt;setProperty("class", "mandatory QLabel"); styleSheetEditor = new StyleSheetEditor(this); statusBar()-&gt;addWidget(new QLabel(tr("Ready"))); connect(ui.exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(ui.aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); } void MainWindow::on_editStyleAction_triggered() { styleSheetEditor-&gt;show(); styleSheetEditor-&gt;activateWindow(); } void MainWindow::on_aboutAction_triggered() { QMessageBox::about(this, tr("About Style sheet"), tr("The &lt;b&gt;Style Sheet&lt;/b&gt; example shows how widgets can be styled " "using &lt;a href=\"http://qt.nokia.com/doc/4.5/stylesheet.html\"&gt;Qt " "Style Sheets&lt;/a&gt;. Click &lt;b&gt;File|Edit Style Sheet&lt;/b&gt; to pop up the " "style editor, and either choose an existing style sheet or design " "your own.")); } </code></pre> <p>Can anyone explain why it awakens with the contents of a *.ui file in my resources?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload