Start changing the code equals prooblemss!!
Ok I dont seem to know why when I do this:
Code:
void MainWindow
::accionFinalizada_Cancelada (QString url
){ //-----------IMAGEN CENTRAL---------
if (url.
contains (QString ("ya_cerramos"))) else{
RandomInfo *randurl = new RandomInfo ();
bg
= QPixmap (randurl
->getRandomUrl
());
} ui->setupUi (this);
this->ui->label_imagen->setPixmap (bg);
this->ui->label_author->hide ();
this->ui->label_text->hide ();
this->ui->menuBar->show ();
}
void MainWindow::on_actionFacturacion_triggered()
{
this->ui->menuBar->hide ();
tipo_factura->exec ();
wfact = new widgetFacturacion(this, this->handler, tipo_factura->getTipoFactura ());
this->setCentralWidget (wfact);
connect (wfact,
SIGNAL(widgetClosed
(QString )) ,
this,
SLOT(accionFinalizada_Cancelada
(QString)));
wfact->show ();
}
(Seccond method triggers first)...the menuBar only works once. I mean, I can click an action for the first time. The action triggers perfecly, but then after setting the ui again, I can navigate through the menu but none of the actions is triggered...any suggestions what that can be? I dont receive any errors nor compiling nor the execution i can click the menu for an hour but nothing happens!!
Re: Start changing the code equals prooblemss!!
Oh my! Here are a few observations/questions to get you thinking:
- You completely rebuild the Designer Ui when you close the second window... what do you think happens to the previously allocated widgets etc.?
- When you rebuild the Ui it runs connectSlotsByName(), and dutifully connects each slot to the first matching child object with a matching signal. Which widget/action will that be? Which widget/action is the menu bar you are clicking on?
- You really need to look at QStackedWidget or hide() the main window while an independent widgetFacturacion window is shown
Re: Start changing the code equals prooblemss!!
OH Lord!!
1) Got it, rebuild the Ui == lost previous data.
2) Yep they are being connected to the ""previous"" menuBar, that`s why I clicked and nothing happened. Im going to explain why im doing this: I have a close button (and a bunch of other label`s and widget, and of course the menuBar). When I close the widgetFacturacion ( I call the method close () ) I try to do the following operations
Code:
this->ui->menuBar->show ();
this->ui->closeButton->show (); // here I get SegFault
with no luck. I mean, why I can show the MenuBar and not the closebutton (wich is inside a central Widget).
3) I`ll give it a read and tell you how this goes.
Re: Start changing the code equals prooblemss!!
BTW: Save yourself some tying and drop the "this->" which is implied anyway.
Re: Start changing the code equals prooblemss!!
Lol, it is something I can`t get rid. At university last year they taught/obliged us to do like this with simple methods:
Code:
void MyClass::MYMethodSetsAvalue (int value){
this->value = value;
}
so from then on Its like riding a bike :P
BTW, any thoughts of my point 2) ?
Added after 9 minutes:
Chris,
I tried your approach of hiding the mainWindow. The thing is that, in that case I need to execute the Widgets in another window because every form/dialog is part of the central widget of the mainWindow. I mean I like it that way, I dont want my mom to think shes opening new windows with every click :P
Added after 36 minutes:
Before you waste your time: QstackedWidget is the holy blessed solution :cool: As I will have only two widgets top in my stack, managing them is quite easy. I post the solution:
Code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
handler = -1;
ui->menuBar->setCornerWidget(corner);
stack_ventanas->addWidget (this->ui->centralWidget);
stack_ventanas->show ();
this->setCentralWidget (stack_ventanas);
}
void MainWindow
::accionFinalizada_Cancelada (QString url
){ //-----------IMAGEN CENTRAL---------
if (url.
contains (QString ("ya_cerramos"))) else{
RandomInfo *randurl = new RandomInfo ();
bg
= QPixmap (randurl
->getRandomUrl
());
}
this->ui->label_imagen->setPixmap (bg);
this->ui->label_author->hide ();
this->ui->label_text->hide ();
if (stack_ventanas->currentIndex () != 0){
stack_ventanas->removeWidget (stack_ventanas->widget (1));
stack_ventanas->setCurrentIndex (0);
}
this->ui->menuBar->show ();
}
void MainWindow::on_actionFacturacion_triggered()
{
this->ui->menuBar->hide ();
tipo_factura->exec ();
wfact = new widgetFacturacion(this, this->handler, tipo_factura->getTipoFactura ());
connect (wfact,
SIGNAL(widgetClosed
(QString )) ,
this,
SLOT(accionFinalizada_Cancelada
(QString)));
stack_ventanas->addWidget (wfact);
}
What you have to be careful is not to set any centralWidget of the mainWindow anymore.
BTW: you can correct any spell mistakes you see (and im talking specially of what I write here, not the code :D), Im here to learn QT and English Lol :P
Thank you very much for the hint on Stacked widgets, my code is pretty neat now :D