Note that there are some explanatory texts on larger screens.

plurals
  1. POadding widget dynamically in qt
    text
    copied!<p>I have a small problem with adding widget to QMainWindow. When i do it like that:</p> <pre><code>wsk_mainStatki = new mainStatki(this); wsk_mainStatki -&gt;setGeometry(0,0,400,300); this-&gt;layout()-&gt;addWidget(wsk_mainStatki); </code></pre> <p>it's ok but i get warning:</p> <blockquote> <p>QMainWindowLayout::addItem: Please use the public QMainWindow API instead</p> </blockquote> <p>this is my game class</p> <pre><code> #include "game.h" game::game() { setGeometry(200, 200, 400, 300); setWindowTitle("Statki"); wsk_mainStatki = new mainStatki(this); wsk_mainStatki -&gt;setGeometry(0,0,400,300); this-&gt;layout()-&gt;addWidget(wsk_mainStatki); } </code></pre> <p>game header</p> <pre><code>#ifndef WIDGET1_H #define WIDGET1_H #include "k_plansza.h" #include "mainStatki.h" #include "settings.h" #include &lt;QApplication&gt; #include &lt;QMainWindow&gt; class game : public QMainWindow { public: game(); ~game() {}; private: mainStatki *wsk_mainStatki; settings *wsk_settings; }; #endif // WIDGET1_H </code></pre> <p>mainstatki class</p> <pre><code>#include "mainstatki.h" mainStatki::mainStatki(QWidget *parent){ setupUi(this); connect(closeButton, SIGNAL(clicked()), parent, SLOT(close())); } </code></pre> <p>mainstatki header</p> <pre><code>#ifndef MAINSTATKI_H #define MAINSTATKI_H #include &lt;QWidget&gt; #include "ui_mainStatki.h" class mainStatki : public QWidget, public Ui::mainStatki { Q_OBJECT public: mainStatki(QWidget *parent); }; #endif // MAINSTATKI_H </code></pre> <p>How it should look? </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