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]Cannot execute my slot when menu item was clicked.

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.8k 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.
  • C Offline
    C Offline
    count
    wrote on last edited by
    #1

    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
    0
    • T Offline
      T Offline
      tony
      wrote on last edited by
      #2

      Hi,

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

      T.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        count
        wrote on last edited by
        #3

        Hi.

        Of course. I just added them to the post.

        Thanks.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          count
          wrote on last edited by
          #4

          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
          0

          • Login

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