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. QDialog::exec react after 3 calls
Forum Updated to NodeBB v4.3 + New Features

QDialog::exec react after 3 calls

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 7.6k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    Nekromancer
    wrote on last edited by
    #5

    cpp:

    @#include "numberpick.h"
    #include "ui_numberpick.h"

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

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

    void NumberPick::setCell(Cell *cell)
    {
    this->cell = cell;
    }

    void NumberPick::on_pushButton_11_clicked()
    {
    //przycisk "zatwierdź"
    this->hide();
    }

    void NumberPick::on_pushButton_10_clicked()
    {
    //przycisk "wyzeruj pole"
    this->cell->setVal(0);
    this->hide();
    }@

    h:

    @#ifndef NUMBERPICK_H
    #define NUMBERPICK_H

    #include <QDialog>
    #include "Cell.h"

    namespace Ui {
    class NumberPick;
    }

    class NumberPick : public QDialog
    {
    Q_OBJECT

    public:
    explicit NumberPick(QWidget *parent = 0);
    ~NumberPick();
    void setCell(Cell * cell);

    private slots:
    void on_pushButton_11_clicked();

    void on_pushButton_10_clicked();
    

    private:
    Ui::NumberPick *ui;
    Cell * cell;
    };

    #endif // NUMBERPICK_H
    @

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #6

      thats strange... do you connect to the slot multiple times maybe?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nekromancer
        wrote on last edited by
        #7

        Actually i don't connect it myself. QtCreator did all the job, i just right-clicked TableView and clicked "go to slot".
        Though there is a little fact about my TableView. I'm painting all its cells with delegate. Could that be important?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #8

          no that's not the problem.
          You problem is that QDialog::exec() gets called multiple times. But your dialog implementation is very simple and i don't see any code where this should happen. There must be some place where the exec() is called again...

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Nekromancer
            wrote on last edited by
            #9

            Nope, no other place.. whole code of my event:

            @void MainWindow::on_boardView_clicked(const QModelIndex &index)
            {
            QPoint point = QCursor::pos();
            point.setX(point.x() - this->numberPick.width() / 2);
            point.setY(point.y() - this->numberPick.height() / 2);

            Cell * cell = this->delegate->getSudoku()->getCell(index.row()+1, index.column()+1);
            if(cell->getClicked() && !cell->getFixed()){
                //TODO : naprawić wyskakujące okienko
                this->numberPick.setCell(cell);
                this->numberPick.move(point);
                this->numberPick.setWindowFlags(Qt::SplashScreen);
                this->numberPick.setParent(this);
                this->numberPick.setModal(true);
                this->numberPick.exec&#40;&#41;;
                this->ui->boardView->viewport()->update();
            }else{
                this->delegate->getSudoku()->clickCell(index.row()+1, index.column()+1);
                this->ui->boardView->viewport()->update();
            }
            cell->setClicked(true);
            

            }@

            There is no other place that dialog could be used

            1 Reply Last reply
            0
            • N Offline
              N Offline
              Nekromancer
              wrote on last edited by
              #10

              Ok i did little workaround and here's my result:

              @this->numberPick = new NumberPick(this);
              this->numberPick->setCell(cell);
              this->numberPick->move(point);
              this->numberPick->setWindowFlags(Qt::SplashScreen);
              this->numberPick->exec();
              delete this->numberPick;@

              It works, but every time i open this dialog i get this message like 20 times "nativeResourceForWindow: 'handle' requested for null window or window without handle.". Should i fix that or no need to be worried (couse whole app works great now)?

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #11

                now i got whats wrong with your code from the first post ;)

                Your hiding of the dialog is wrong.

                Since you start your dialog with QDialog::exec() a new event loop is started. In this case you shouldn't "close" the dialog with a simple hide() call, because this just hides the dialog but the started event loop remains and isn't left. There you have your multiple call of exec() i was talking before.

                You should use QDialog::done() instead which closes the dialog and returns from the event loop.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  Nekromancer
                  wrote on last edited by
                  #12

                  and which code would be better? Creating a new window every time could have impact on application performance, right?

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #13

                    you won't notice a significant impact on performance.
                    The best would be to create it on the heap (using "new") and reuse it. Thus it is only created if it is needed once.
                    Initialize the pointer to "0" and only create the dialog if the pointer is "0". Otherwise just call exec() on it:
                    @
                    if( ! numberPick )
                    {
                    //create and initialize dialog
                    }
                    numberPick.exec();
                    @

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      Nekromancer
                      wrote on last edited by
                      #14

                      Ok, all works just fine. Thx for your help!

                      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