• 7159阅读
  • 4回复

[提问]程序运行正常,控制台提示Object::connect: No such slot [复制链接]

上一主题 下一主题
离线yinrenjieone
 

只看楼主 倒序阅读 楼主  发表于: 2011-07-27
关键词: 编译QString
程序能够编译通过,运行各项功能也都正常。
但是运行时总提示:
Object::connect: No such slot MainWindow::on_action_set_triggered(bool b)
Object::connect:  (sender name:   'action_set')
Object::connect:  (receiver name: 'MainWindow')
Object::connect: No such slot MainWindow::on_action_about_triggered(bool b)
Object::connect:  (sender name:   'action_about')
Object::connect:  (receiver name: 'MainWindow')

代码如下:
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();    

private slots:
    void on_pushButton_openData_clicked();
    void on_action_set_triggered(bool b);
    void on_action_exit_triggered();
    void on_action_about_triggered(bool b);

    void on_pushButton_savePath_clicked();

    void on_pushButton_set_clicked();

    void on_pushButton_tran_clicked();

private:
    Ui::MainWindow *ui;
    QString dataFilePath;
    QString savePath;
    QString log;

    void tra();
    void connectsInit();
    void readSettings();
    void sleep(unsigned int ms);
};

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connectsInit();
    readSettings();

    ui->pushButton_tran->setEnabled(false);

    int x = (QApplication::desktop()->width() - width()) / 2;
    int y = (QApplication::desktop()->height() - height()) * 0.382;
    move(x, y);
}

void MainWindow::connectsInit()
{
    connect(ui->action_set, SIGNAL(triggered(bool)), this, SLOT(on_action_set_triggered(bool b)));
    connect(ui->action_exit, SIGNAL(triggered()), this, SLOT(on_action_exit_triggered()));
    connect(ui->action_about, SIGNAL(triggered(bool)), this, SLOT(on_action_about_triggered(bool b)));
}
离线dbzhang800

只看该作者 1楼 发表于: 2011-07-27
connect写错了。如果你确信工作正常,那就是不但错了,而且和自动connect重复了,不用改,直接去掉它。
离线yinrenjieone

只看该作者 2楼 发表于: 2011-07-27
引用第1楼dbzhang800于2011-07-27 12:18发表的  :
connect写错了。如果你确信工作正常,那就是不但错了,而且和自动connect重复了,不用改,直接去掉它。

改为
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //connectsInit();
    readSettings();

    ui->pushButton_tran->setEnabled(false);

    int x = (QApplication::desktop()->width() - width()) / 2;
    int y = (QApplication::desktop()->height() - height()) * 0.382;
    move(x, y);
}
之后确实不在提示了,而且点击action也执行正常。
但是,没有调用connect的话,我的action是如何与slot连接上的呢?
离线hyqlxf

只看该作者 3楼 发表于: 2011-07-27
回 2楼(yinrenjieone) 的帖子
再窗口设计里面直接右键go to slot出来的函数全部都是已经连接好的,直接写函数内容就行不需要再连接
离线yinrenjieone

只看该作者 4楼 发表于: 2011-07-27
Re:回 2楼(yinrenjieone) 的帖子
引用第3楼hyqlxf于2011-07-27 12:33发表的 回 2楼(yinrenjieone) 的帖子 :
再窗口设计里面直接右键go to slot出来的函数全部都是已经连接好的,直接写函数内容就行不需要再连接

我的这些action是菜单menu里的,用qt creator的时候右键没有go to slot,所以只好自己写connect……
快速回复
限100 字节
 
上一个 下一个