找回密码
 立即注册
收起左侧

1个界面中2个按钮分别打开不同的子界面,如何实现

9
回复
7301
查看
[复制链接]
累计签到:9 天
连续签到:1 天
来源: 2016-10-19 10:07:03 显示全部楼层 |阅读模式
2Qter豆
我在一个界面中设置2个按钮,让这两个按钮分别打开对应的子界面,在main.cpp中,如何编程,在.ui中,2个按钮的信号和槽如何设置。

回复

使用道具 举报

累计签到:1568 天
连续签到:1 天
2016-10-19 10:26:38 显示全部楼层
回复

使用道具 举报

累计签到:9 天
连续签到:1 天
2016-10-19 14:38:35 显示全部楼层
本帖最后由 米兰6号 于 2016-10-19 14:50 编辑
yafeilinux 发表于 2016-10-19 10:26
建议学习一遍http://www.qter.org/forum.php?mod=viewthread&tid=193教程。

大神,您好!
我在编写子窗口时
dialog1.cpp程序如下:
#include "dialog1.h"
#include "ui_dialog1.h"

Dialog1:ialog1(QWidget *parent) :
    QDialog(parent),
    ui(new Ui:ialog1)
{
    ui->setupUi(this);
}

Dialog1::~Dialog1()
{
    delete ui;
}
void Dialog1:n_pushButton_clicked()
{
    this->close();
}


头文件dialog1.h
#ifndef DIALOG1_H
#define DIALOG1_H

#include <QDialog>

namespace Ui {
class Dialog1;
}

class Dialog1 : public QDialog
{
    Q_OBJECT

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

private:
    Ui:ialog1 *ui;
};

#endif // DIALOG1_H


可是在编写后显示报警:
error: no 'void Dialog1:n_pushButton_clicked()' member function declared in class 'Dialog1'

没找到问题的原因,请大神帮忙解答,谢谢!




回复

使用道具 举报

累计签到:9 天
连续签到:1 天
2016-10-19 14:51:12 显示全部楼层
米兰6号 发表于 2016-10-19 14:38
大神,您好!
我在编写子窗口时
dialog1.cpp程序如下:

可是在mainwindow.cpp中,
#include "mainwindow.h"
#include "ui_mainwindow.h"

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

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow:n_pushButton_clicked()
{
     this->hide();
     dialog1.show();
     dialog1.exec();
     this->show();
}
void MainWindow:n_pushButton_2_clicked()
{
    this->close();
}
void MainWindow:n_pushButton_3_clicked()
{
    this->hide();
    dialog2.show();
    dialog2.exec();
    this->show();
}
这样写,编译就没出问题。
回复

使用道具 举报

累计签到:9 天
连续签到:1 天
2016-10-19 15:37:13 显示全部楼层
问题已解决,感谢“夜风之翼”朋友的帮忙,再次感谢论坛里的各位朋友,拜谢!
回复

使用道具 举报

累计签到:9 天
连续签到:1 天
2016-10-19 15:38:52 显示全部楼层
class Dialog1 : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog1(QWidget *parent = 0);
    ~Dialog1();
    Q_SLOT void on_pushButton_clicked( );
private:
    Ui:ialog1 *ui;
};
在头文件中增加Q_SLOT void on_pushButton_clicked( );
回复

使用道具 举报

累计签到:1568 天
连续签到:1 天
2016-10-20 10:55:34 显示全部楼层
米兰6号 发表于 2016-10-19 15:38
class Dialog1 : public QDialog
{
    Q_OBJECT

你没有声明就用了!
回复

使用道具 举报

累计签到:9 天
连续签到:1 天
2016-10-20 16:30:53 显示全部楼层
yafeilinux 发表于 2016-10-20 10:55
你没有声明就用了!

是的,我是初学者,这些语法规则我没找到,F1帮助按键下面看到关于Q_SLOT的说明,也没有看到语法规则的解释。看来我得从头到尾看一遍了,在您的教程里有相关知识的介绍么,大神。
回复

使用道具 举报

累计签到:1568 天
连续签到:1 天
2016-10-22 11:45:42 显示全部楼层
米兰6号 发表于 2016-10-20 16:30
是的,我是初学者,这些语法规则我没找到,F1帮助按键下面看到关于Q_SLOT的说明,也没有看到语法规则的解 ...

这是C++基础知识,需要学习C++
回复

使用道具 举报

累计签到:9 天
连续签到:1 天
2016-10-24 16:43:56 显示全部楼层
yafeilinux 发表于 2016-10-22 11:45
这是C++基础知识,需要学习C++

谢谢,我同步学习一下c++基础支持。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了