Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    [SOLVED]Cannot execute my slot when menu item was clicked.

    General and Desktop
    2
    4
    3615
    Loading More Posts
    • 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.
    • C
      count last edited by

      Hi All!
      May be some of you know how to help me.

      I want create menu in my programm, then i tried to connect new menu item with my private slot via next code:
      @connect(ui->newPack, SIGNAL(triggered()), this, SLOT(addNew()));@

      But, when menu item was clicked nothing was happens. If i write:
      @ui->newPack->trigger();@
      slot addNew() executes, thus connection works.

      Also, if i write:
      @connect(ui->newPack, SIGNAL(triggered()), this, SLOT(close()));@
      it works fine...

      Thanks.

      UPD
      There is sources.
      mainwindow.h file:
      @namespace Ui {
      class MainWindow;
      }

      class MainWindow : public QMainWindow {
      Q_OBJECT
      public:
      MainWindow(QWidget *parent = 0);
      ~MainWindow();

      protected:
      void changeEvent(QEvent *e);

      private:
      Ui::MainWindow *ui;

      private slots:
      void addNew();
      };@

      mainwindow.cpp file:
      @MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
      {
      ui->setupUi(this);
      connect(ui->newPack, SIGNAL(triggered()), this, SLOT(addNew()));
      }

      void MainWindow::addNew()
      {
      ui->mdiArea->addSubWindow(new QuestionList);
      ...
      }@

      1 Reply Last reply Reply Quote 0
      • T
        tony last edited by

        Hi,

        can you post the code we're talking about? That's not so clear ...

        T.

        1 Reply Last reply Reply Quote 0
        • C
          count last edited by

          Hi.

          Of course. I just added them to the post.

          Thanks.

          1 Reply Last reply Reply Quote 0
          • C
            count last edited by

            Oh. The problem was that added QMdiSubWindow didn't shown automaticaly, then, when i execute addNew from window constructor it's executes and shown correctly, but, in other cases i should execute qMdiSubWindow->show(); manually.
            Now AddNew slot looks like this:
            @void MainWindow::addNew()
            {
            ui->mdiArea->addSubWindow(new QuestionList);
            ...
            ui->mdiArea->subWindowList().last()->show();
            }@
            and all works fine.

            Never mind.

            Thank you.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post