Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Crash When show full screen
QtWS25 Last Chance

[Solved]Crash When show full screen

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 6.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vetryaspa
    wrote on last edited by
    #1

    Hi all,

    can someone explaim me why if i make this the application crash?

    @MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    chiamaIMigliori();
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::chiamaIMigliori(){

    IMigliori *schermataMIgliori = new IMigliori();
    schermataMIgliori->showFullScreen();
    

    }
    @

    and Class "IMigliori"

    @IMigliori::IMigliori(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::IMigliori)
    {
    ui->setupUi(this);

    listaWidget *lista = new listaWidget();
    this->layout()->addWidget(lista);
    

    }

    IMigliori::~IMigliori()
    {
    delete ui;
    }
    @

    why if i try to do this the app crash and if i set the follow code it run?

    @MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    // chiamaIMigliori();

    listaWidget *lista = new listaWidget();
    this->layout()->addWidget(lista);
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    the error is: @The program has unexpectedly finished.@

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Did you try to run it in the debugger?
      that should give you the position in the code where the application is crashing.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        Does IMigliori have a valid layout set?
        @
        this->layout()->addWidget(lista); // crashes when there is no layout set
        @
        In addition, be aware that the IMigliore instance has no parent and the pointer is created on the stack and goes out of scope when MainWindow::chiamaIMigliori() is left - you will lose your only reference to the widget (there is QApplication::topLevelWidgets(), but it won't let you distinct between multiple IMigliore instances, as you have no object name set).

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vetryaspa
          wrote on last edited by
          #4

          [quote author="Lukas Geyer" date="1330584726"]Does IMigliori have a valid layout set?
          @
          this->layout()->addWidget(lista); // crashes when there is no layout set
          @
          In addition, be aware that the IMigliore instance has no parent and the pointer is created on the stack and goes out of scope when MainWindow::chiamaIMigliori() is left - you will lose your only reference to the widget (there is QApplication::topLevelWidgets(), but it won't let you distinct between multiple IMigliore instances, as you have no object name set).[/quote]

          so how i can solve this problem? with QLayout?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5
            • Make sure you have selected a layout for your top-level widget in the designer.
            • Make schermataMIgliori a member of your class.
            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vetryaspa
              wrote on last edited by
              #6

              [quote author="Lukas Geyer" date="1330590798"]* Make sure you have selected a layout for your top-level widget in the designer.[/quote]
              how I can do this? how a can select a layout from designer? I have to create a widget in the designer and then set my custom widget "listaWidget " same to ui widget?

              [quote author="Lukas Geyer" date="1330590798"]*Make schermataMIgliori a member of your class.[/quote]
              how i can set schermataMIgliori member of mainWindow?

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vetryaspa
                wrote on last edited by
                #7

                ok I have make some test and the main window don't execute the @showFullScreen()@ of schermataMIgliori....

                Why?????
                O.o

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  [quote author="Vetryaspa" date="1330591900"]
                  how I can do this? how a can select a layout from designer? I have to create a widget in the designer
                  and then set my custom widget "listaWidget " same to ui widget?[/quote]
                  Make sure you have selected the top-level widget and <Rightclick> -> Layout and select the desired layout.

                  [quote author="Vetryaspa" date="1330591900"]
                  how i can set schermataMIgliori member of mainWindow? [/quote]
                  @
                  class MainWindow : public QMainWindow
                  {
                  ...
                  private:
                  IMigliori *schermataMIgliori;
                  }
                  @
                  [quote author="Vetryaspa" date="1330591900"]ok I have make some test and the main window don’t execute the[/quote]
                  Well, it's pretty hard to tell what's going wrong without showing any code. Provide an small, compilable example to get furher help.

                  And if you want a honest answer: the source of your problems seems to be a lack of basic knowledge of C++, Qt and its tools. I would start with having a good read on these topics first.

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Vetryaspa
                    wrote on last edited by
                    #9

                    ok i have understand that the problem is where i doing show of IMigliori because i have make this and the class was show:

                    @MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent), ui(new Ui::MainWindow)
                    {
                    ui->setupUi(this);
                    // chiamaIMigliori();

                    // schermataMIgliori = new IMigliori();
                    // schermataMIgliori->showFullScreen();
                    }

                    MainWindow::~MainWindow()
                    {
                    delete ui;
                    }

                    void MainWindow::paintEvent(QPaintEvent *event){
                    qDebug()<< "PAINT EVENT MAINWINDOW";
                    schermataMIgliori = new IMigliori();
                    schermataMIgliori->showFullScreen();
                    }@

                    now it was show();

                    i have try to found somting to creat and set a custom Widget class in a view but i not have found nothing to intrest me...

                    however now the window was call but if i set this:

                    @IMigliori::IMigliori(QWidget *parent) :
                    QWidget(parent),
                    ui(new Ui::IMigliori)
                    {
                    ui->setupUi(this);
                    }

                    IMigliori::~IMigliori()
                    {
                    delete ui;
                    }

                    void IMigliori::paintEvent(QPaintEvent *event){
                    qDebug()<< "PAINT EVENT IMIGLIORI";

                    listaWidget *lista = new listaWidget();
                    this->layout()->addWidget(lista);
                    

                    }
                    @

                    the widget was not show... I have compere the XML ui of MainWindow with the IMigliori and i have see this row at the MainWindow

                    @ <layoutdefault spacing="6" margin="11"/>@

                    is possible to set somting like this in the other designer?
                    i have see all of standard layout but no one of this if for project. i need to be free to developer the app.... and using layout is not good.... so there is another way to set the widget in the class IMigliori?

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      Vetryaspa
                      wrote on last edited by
                      #10

                      ok i have add the widget in LayoutBox like this:

                      @IMigliori::IMigliori(QWidget *parent) :
                      QWidget(parent),
                      ui(new Ui::IMigliori)
                      {
                      ui->setupUi(this);
                      lista = new listaWidget();
                      lista->setGeometry(QRect(0,100,360,400));
                      QVBoxLayout *layout = new QVBoxLayout;
                      layout->addWidget(lista);
                      setLayout(layout);
                      qDebug()<<lista->geometry();
                      }

                      IMigliori::~IMigliori()
                      {
                      delete ui;
                      }

                      void IMigliori::paintEvent(QPaintEvent *event){
                      qDebug()<< "PAINT EVENT IMIGLIORI";
                      qDebug()<<lista->geometry();
                      }
                      @

                      but my problem now is the geometry of "listaWidget" because it paint a lis of object but the list occupies all screen and I wont it but i wont that respect a dimensione setted...

                      i have to modify a paintEvent in the "listaWidget" class?

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        lgeyer
                        wrote on last edited by
                        #11

                        Do yourself a favor and grab a good book on Qt and start reading it instead - they are even available "for free":http://www.qtrac.eu/marksummerfield.html - or at least take a look at the excellent "documentation":http://developer.qt.nokia.com/doc/qt-4.8/how-to-learn-qt.html that comes with Qt.

                        There is so much wrong with your code I honestly do not even know where to start; and even if I would I see no sense in it before you've gathered fundamental knowledge (this is no shame at all, we all started at this point somewhen), which is essential for doing any programming, with or without Qt.

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          Vetryaspa
                          wrote on last edited by
                          #12

                          ok... sorry... i have see now that i not have set Widget parent in the "listaWidget"

                          i have solved all problem setting in the class

                          @explicit listaWidget(QWidget *parent = 0);@

                          and then simply write:

                          @lista = new listaWidget(this);@

                          al run perfectly

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved