Results 1 to 5 of 5

Thread: Start changing the code equals prooblemss!!

  1. #1
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    33
    Thanked 10 Times in 10 Posts

    Default Start changing the code equals prooblemss!!

    Ok I dont seem to know why when I do this:

    Qt Code:
    1. void MainWindow::accionFinalizada_Cancelada (QString url){
    2. //-----------IMAGEN CENTRAL---------
    3. QPixmap bg;
    4. if (url.contains (QString ("ya_cerramos")))
    5. bg = QPixmap (url);
    6. else{
    7. RandomInfo *randurl = new RandomInfo ();
    8. bg = QPixmap (randurl->getRandomUrl ());}
    9. ui->setupUi (this);
    10. this->ui->label_imagen->setPixmap (bg);
    11. this->ui->label_author->hide ();
    12. this->ui->label_text->hide ();
    13. this->ui->menuBar->show ();
    14. }
    15.  
    16. void MainWindow::on_actionFacturacion_triggered()
    17. {
    18. this->ui->menuBar->hide ();
    19. tipo_factura->exec ();
    20. wfact = new widgetFacturacion(this, this->handler, tipo_factura->getTipoFactura ());
    21. this->setCentralWidget (wfact);
    22. connect (wfact, SIGNAL(widgetClosed (QString )) ,this, SLOT(accionFinalizada_Cancelada(QString)));
    23. wfact->show ();
    24. }
    To copy to clipboard, switch view to plain text mode 

    (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!!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default 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

  3. The following user says thank you to ChrisW67 for this useful post:

    KillGabio (10th February 2012)

  4. #3
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    33
    Thanked 10 Times in 10 Posts

    Default 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

    Qt Code:
    1. this->ui->menuBar->show ();
    2. this->ui->closeButton->show (); // here I get SegFault
    To copy to clipboard, switch view to plain text mode 
    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.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Start changing the code equals prooblemss!!

    BTW: Save yourself some tying and drop the "this->" which is implied anyway.

  6. #5
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    33
    Thanked 10 Times in 10 Posts

    Default 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:

    Qt Code:
    1. void MyClass::MYMethodSetsAvalue (int value){
    2. this->value = value;
    3. }
    To copy to clipboard, switch view to plain text mode 

    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 As I will have only two widgets top in my stack, managing them is quite easy. I post the solution:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. handler = -1;
    7. ui->menuBar->setCornerWidget(corner);
    8. stack_ventanas = new QStackedWidget;
    9. stack_ventanas->addWidget (this->ui->centralWidget);
    10. stack_ventanas->show ();
    11. this->setCentralWidget (stack_ventanas);
    12. }
    13.  
    14. void MainWindow::accionFinalizada_Cancelada (QString url){
    15. //-----------IMAGEN CENTRAL---------
    16. QPixmap bg;
    17. if (url.contains (QString ("ya_cerramos")))
    18. bg = QPixmap (url);
    19. else{
    20. RandomInfo *randurl = new RandomInfo ();
    21. bg = QPixmap (randurl->getRandomUrl ());
    22. }
    23. this->ui->label_imagen->setPixmap (bg);
    24. this->ui->label_author->hide ();
    25. this->ui->label_text->hide ();
    26. if (stack_ventanas->currentIndex () != 0){
    27. stack_ventanas->removeWidget (stack_ventanas->widget (1));
    28. stack_ventanas->setCurrentIndex (0);
    29. }
    30. this->ui->menuBar->show ();
    31. }
    32.  
    33. void MainWindow::on_actionFacturacion_triggered()
    34. {
    35. this->ui->menuBar->hide ();
    36. tipo_factura->exec ();
    37. wfact = new widgetFacturacion(this, this->handler, tipo_factura->getTipoFactura ());
    38. connect (wfact, SIGNAL(widgetClosed (QString )) ,this, SLOT(accionFinalizada_Cancelada(QString)));
    39. stack_ventanas->addWidget (wfact);
    40. }
    To copy to clipboard, switch view to plain text mode 

    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 ), 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
    Last edited by KillGabio; 10th February 2012 at 04:36.

Similar Threads

  1. gdb exited unexpectedly (code 1) on start-up [solved]
    By PowerPlate in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2011, 20:40
  2. Designing transaction in the code equals designing problems
    By kornicameister in forum Qt Programming
    Replies: 8
    Last Post: 3rd February 2011, 02:11
  3. override hash set and equals problem
    By mickey in forum General Programming
    Replies: 1
    Last Post: 9th September 2010, 19:28
  4. Changing a file extension inside the code
    By fortyhideout12 in forum Qt Programming
    Replies: 6
    Last Post: 19th February 2010, 22:20
  5. Replies: 2
    Last Post: 10th August 2009, 10:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.