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



  • 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);
    ...
    }@



  • Hi,

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

    T.



  • Hi.

    Of course. I just added them to the post.

    Thanks.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.