How to develop a multi-gui application "alternative for the stacked widget "
Hello i am a beginner my objective is to develop a multi interfaces application where each interface "widget" had it's own .cpp and .h files .
my second question is how to link them up
i want an application which is similar in the structure and the classes to an android application where each interface has it's specifics files :confused: :confused:
Re: How to develop a multi-gui application "alternative for the stacked widget "
Re: How to develop a multi-gui application "alternative for the stacked widget "
i know already that but the stackedwidget doesn't allow me to seperate the code of each page "widget" in a separated .cpp and .h file
Re: How to develop a multi-gui application "alternative for the stacked widget "
Of course it allows you to implement the code of each page in a separate set of files.
Re: How to develop a multi-gui application "alternative for the stacked widget "
how is that ??? I have already tried it but when implement a new page in the QstackedWidget i don't get a new set of files for the new page
Re: How to develop a multi-gui application "alternative for the stacked widget "
QStackedWidget::addWidget() -- this accepts pointer to a widget. Any widget. Implemented in any file.
Re: How to develop a multi-gui application "alternative for the stacked widget "
Sorry for asking again but i have a problem using this method
i have created a new QtDesignerForm class called Widget2
do i call this widget like this ??
ui->stackedWidget->addWidget(Widget2 );
Re: How to develop a multi-gui application "alternative for the stacked widget "
Quote:
do i call this widget like this ??
ui->stackedWidget->addWidget(Widget2 );
No. You do this:
Code:
Widget2 * newWidget2 = new Widget2;
ui->stackedWidget->addWidget( newWidget2 );
As Wysota said, the code for "Widget2" can be implemented *anywhere*. It can even be implemented in a library (such as Qt itself) and all you need to create an instance of "Widget2" is the header file that defines the class and the library containing the compiled code.
If you are trying to create new QWidget classes of your own and you are not ending up with new .h and .cpp files in which to implement the code for those classes, then you are not using your application development tool correctly or you have it configured wrong.
Re: How to develop a multi-gui application "alternative for the stacked widget "
Well at first i created in my project a new Qt Designer Form Class which is a widget called widget2 that created an new .ui/.cpp/.h files then i wrote this code in my mainwindow wich contain a QStackedWidget
Code:
ui->stackedWidget->setCurrentIndex(0);
Widget2 * newWidget2 = new Widget2;
ui->stackedWidget->addWidget( newWidget2 );
but i doesn't do the job :mad: :mad:
Re: How to develop a multi-gui application "alternative for the stacked widget "
In what way "it doesn't do the job"?
Re: How to develop a multi-gui application "alternative for the stacked widget "
Quote:
Originally Posted by
wysota
In what way "it doesn't do the job"?
Well simply i don't get that interface when i start the application i get just an empty interface which is the interface for the QStackedwidget
Added after 5 minutes:
this is the code of my mainWindow
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "widget2.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->stackedWidget->setCurrentIndex(0);
Widget2 *newWidget2 = new Widget2;
ui->stackedWidget->addWidget(newWidget2);
}
MainWindow::~MainWindow()
{
delete ui;
}
Re: How to develop a multi-gui application "alternative for the stacked widget "
I'm assuming your stack widget has two pages that are added to it by default by Designer so if you set current index to 0, you see one of those two blank pages. Either delete those two pages or set current index to 2.
Re: How to develop a multi-gui application "alternative for the stacked widget "
Setting the index to 2 didn't do the job neither deleting because there's no way to delete the default 2 pages created by the Designer
Added after 5 minutes:
I am currently working on OpenSUSE 12 64Bit and my Qt is Qt Creator 2.5.0 Based on Qt 4.8.1 (64 bit)
Re: How to develop a multi-gui application "alternative for the stacked widget "
Quote:
Originally Posted by
sliverTwist
Setting the index to 2 didn't do the job
A riddle for you: if a book has 10 pages and you try turning to page 123 then it won't work. But if a book has 123 pages then it will work.
Quote:
neither deleting because there's no way to delete the default 2 pages created by the Designer
I don't have any problems deleting pages created by Designer.
Re: How to develop a multi-gui application "alternative for the stacked widget "
Alternatively fill the stack with empty widgets for each page in designer and then promote each of those to the class that should be at the respective page.
So for example if you want Widget2 to be the first page, promote the widget in page 1 to type Widget2.
Cheers,
_
Re: How to develop a multi-gui application "alternative for the stacked widget "
Quote:
neither deleting because there's no way to delete the default 2 pages created by the Designer
In the Object browser pane:
- Right-click on the stacked widget
- Select Page 1 of 2 from the context menu
- Select Delete
- Rinse and repeat
Or, because TMTOWTDI, you can do it in code:
Code:
QWidget *widget
= ui
->stackedWidget
->index
(0);
ui->stackedWidget->removeWidget(widget);
widget->deleteLater();