Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp getting started with Qt to design a basic GUI
    primarykey
    data
    text
    <p>For our semester lab examination, we need to make a GUI which lists all the programs under different categories and opens them when we'd click on one of them. I don't really know GUI programming but know the basics of C++ and thought that Qt would be a good choice to start with. I'm working with QtCreator and it seems like a pretty slick tool.</p> <p>What i'm trying to achieve is that when i click a button, the main window should be hidden and the window for the corresponding category should be shown from where i'll execute the required program. I'm using two different classes that inherit from QWidget the HomeWidget and the ProcessWidget for the main window and the process management category respectively. I plan to add more widgets for the other categories but i'm not exactly clear as to how i can glue together these individual widgets.</p> <p>I think that the design choice that i've made isn't appropriate, and i'm not sure of the appropriate design choice. Help regarding this would be much appreciated, the contents of all the files that i'm using is attached below.</p> <p>homewidget.h</p> <pre><code>#ifndef HOMEWIDGET_H #define HOMEWIDGET_H #include &lt;QtGui/QWidget&gt; #include &lt;QVBoxLayout&gt; #include &lt;QHBoxLayout&gt; #include &lt;QLabel&gt; #include &lt;QPushButton&gt; #include "processwidget.h" class HomeWidget : public QWidget { Q_OBJECT private: QVBoxLayout *main_layout; QHBoxLayout *footer; QLabel *header,*footer_text; QPushButton *process_mgt,*file_mgt; QWidget *target; public: HomeWidget(QWidget *parent = 0); ~HomeWidget(); private slots: void process_management_slot(QWidget *qw); }; #endif // HOMEWIDGET_H </code></pre> <p>homewidget.cpp</p> <pre><code>#include "homewidget.h" HomeWidget::HomeWidget(QWidget *parent) : QWidget(parent) { main_layout = new QVBoxLayout(); footer = new QHBoxLayout(); header = new QLabel("&lt;i&gt;MCA Semester 2&lt;/i&gt;\nOS LAB Record"); footer_text = new QLabel("Made By :\n\t Nikhil Bhardwaj"); process_mgt = new QPushButton("Process Management"); file_mgt = new QPushButton("File Management"); setWindowTitle("Operating Systems Lab, MCA NITT 2011"); footer-&gt;addStretch(); footer-&gt;addWidget(footer_text); main_layout-&gt;addWidget(header); main_layout-&gt;addStretch(); main_layout-&gt;addWidget(process_mgt); main_layout-&gt;addWidget(file_mgt); main_layout-&gt;addStretch(); main_layout-&gt;addLayout(footer); setLayout(main_layout); connect(process_mgt,SIGNAL(clicked()),this,SLOT(process_management_slot(process_widget))); } HomeWidget::~HomeWidget() { } void HomeWidget::process_management_slot(QWidget *qw) { this-&gt;hide(); target = qw; target-&gt;show(); } </code></pre> <p>processwidget.h</p> <pre><code>#ifndef PROCESSWIDGET_H #define PROCESSWIDGET_H #include &lt;QWidget&gt; #include &lt;QVBoxLayout&gt; #include &lt;QHBoxLayout&gt; #include &lt;QLabel&gt; #include &lt;QPushButton&gt; class ProcessWidget : public QWidget { Q_OBJECT private: QVBoxLayout *process_layout; QHBoxLayout *process_footer; QLabel *process_header,*process_footer_text; QPushButton *back,*scheduling,*synchronization,*bankers; public: ProcessWidget(QWidget *parent = 0); signals: public slots: }; #endif // PROCESSWIDGET_H </code></pre> <p>processwidget.cpp</p> <pre><code>#include "processwidget.h" ProcessWidget::ProcessWidget(QWidget *parent) : QWidget(parent) { process_layout = new QVBoxLayout(); process_footer = new QHBoxLayout(); process_header = new QLabel("&lt;i&gt;MCA Semester 2&lt;/i&gt;\nOS LAB Record"); process_footer_text = new QLabel("Made By :\n\t Nikhil Bhardwaj"); back = new QPushButton("Main Menu"); scheduling = new QPushButton("Scheduling Algorithms"); setWindowTitle("Operating Systems Lab, Process Management"); process_footer-&gt;addStretch(); process_footer-&gt;addWidget(process_footer_text); process_layout-&gt;addWidget(process_header); process_layout-&gt;addStretch(); process_layout-&gt;addWidget(scheduling); process_layout-&gt;addWidget(back); process_layout-&gt;addStretch(); process_layout-&gt;addLayout(process_footer); setLayout(process_layout); } </code></pre> <p>main.cpp</p> <pre><code>#include &lt;QtGui/QApplication&gt; #include &lt;QVBoxLayout&gt; #include &lt;QHBoxLayout&gt; #include &lt;QLabel&gt; #include &lt;QPushButton&gt; #include "homewidget.h" #include "processwidget.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); HomeWidget *main_widget = new HomeWidget(); ProcessWidget *process_widget = new ProcessWidget(); main_widget-&gt;show(); return a.exec(); } </code></pre> <p>and finally final_gui.pro</p> <pre><code>#------------------------------------------------- # # Project created by QtCreator 2011-04-15T06:37:21 # #------------------------------------------------- QT += core gui TARGET = final_gui TEMPLATE = app SOURCES += main.cpp\ homewidget.cpp \ processwidget.cpp HEADERS += homewidget.h \ processwidget.h </code></pre> <p>I'll be more than happy to clarify if i haven't been clear in explaining my issue.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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