0

这是我的班级声明:

class Browser : public QWidget {    
    Q_OBJECT
    public:
        Browser(QWidget *parent = 0);
        QStringList loadSettings(QString settings_file);
    private slots:
        void toggleFullscreen();               
    private:     
        void createActions();
        QAction *aToggleFullscreen;            
};

和相关定义:

void Browser::toggleFullscreen() {
    out << "fullscreen!" << endl;
}   
void Browser::createActions() {
    aToggleFullscreen = new QAction(this);
    aToggleFullscreen->setShortcut(tr("F11"));    
    connect(aToggleFullscreen, SIGNAL(triggered()), this, SLOT(toggleFullscreen()));    
}

我从 打来createActions()Browser::Browser

我没有运行时警告说插槽不存在等。但如果我点击F11.

我也试过:

aToggleFullscreen->setShortcut(QString("F11"));

我的代码有什么问题?

4

1 回答 1

1

您忘记将您的操作实际添加到浏览器,因此它永远不会被触发。这应该有效:

void Browser::createActions() {
    aToggleFullscreen = new QAction(this);
    aToggleFullscreen->setShortcut(tr("F11"));    
    connect(aToggleFullscreen, SIGNAL(triggered()), this, SLOT(toggleFullscreen()));
    addAction(aToggleFullscreen);    
}
于 2013-01-15T16:30:29.947 回答