PDA

View Full Version : Multi Window Application in QT/C++



pshah.mumbai
5th July 2008, 17:25
I want to create a simple accounting software.

It has a main window with all the menus and other windows for making vouchers, stock, etc..

The main window is main.cpp and other files will be xyz.cpp ,etc.

How do I go about with the application ?

Lets say I click on the "Create ledger" tool button.

Then how do I link the ledger.cpp file and show the Ledger creation dialog ??

jpn
5th July 2008, 18:11
Have you heard of header files? Please learn at least basics of C++ first, then try to use Qt...

See FAQ: I have two forms. How to open a second form after a button is clicked in the first one? (http://www.qtcentre.org/forum/faq.php?faq=qt_general_category#faq_qt_designer_2f orms)

pshah.mumbai
7th July 2008, 18:37
Sorry for not RTFM. I have bought 2 books on QT and none of them explain how to use QT Designer and I spend days figuring it out how to do it.:p

pshah.mumbai
7th July 2008, 18:41
What if I have both the forms designed in QT Designer.

pshah.mumbai
7th July 2008, 18:53
Any good docs on using QT Designer ?

I have created the Menubar in QT Designer and I want that on clicked it calls a function ShowGroups()

How do I access the menubar items created in designer in the .cpp files ?

ps : should I dump the designer and just hand code everything ?? I cant find any good docs for designer...

:crying:

jpn
7th July 2008, 18:55
Qt Designer Manual (http://doc.trolltech.com/4.4/designer-manual.html)

pshah.mumbai
8th July 2008, 16:30
I read the manual but I still cant figure out how to load the 2nd form.

I have two forms
1. mainwindow.ui
2. groupwindow.ui

Below are the files..
main.cpp

#include "ui_mainwindow.h"
//Main program
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Ui::MainWindow ui;
QMainWindow *mainwindow = new QMainWindow;
ui.setupUi(mainwindow);
mainwindow->show();
return app.exec();
}

mainwindow.h

class MainWindow : public QMainWindow, private Ui::MainWindow, private Ui::GroupWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
void InitMenu();
public slots:
void OpenGroupWindow();
};
#endif

mainwindow.cpp

#include "ui_mainwindow.h"
#include "mainwindow.h"
#include "ui_groupwindow.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
InitMenu();
}

void MainWindow::InitMenu()
{
//groupAction is a menu action in the ui file.
connect(actionGroup, SIGNAL(clicked()), this, SLOT(OpenGroupWindow()));
// Nothing happens when I click / triggered the above menu item. The application compiles without any errors.
}

void MainWindow::OpenGroupWindow()
{
QWidget *widget = new QWidget;
Ui::GroupWindow gwui;
gwui.setupUi(widget);
setCentralWidget(widget);
widget->show();
}

pshah.mumbai
8th July 2008, 17:16
ok I am trying out few other things..I will post back if it doesnt work,...

pshah.mumbai
8th July 2008, 17:21
Ook Got It Working !! :d