一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
posts - 3121,comments - 209,views - 578万

一显示效果


二编辑界面如下


三 在mainwindow.h中声明槽函数

复制代码
 1 #ifndef MAINWINDOW_H
 2 #define MAINWINDOW_H
 3  
 4 #include <QMainWindow>
 5 #include <QComboBox>
 6  
 7 namespace Ui {
 8 class MainWindow;
 9 }
10  
11 class MainWindow : public QMainWindow
12 {
13     Q_OBJECT
14  
15 public:
16     explicit MainWindow(QWidget *parent = 0);
17     ~MainWindow();
18     //声明槽函数print_s();
19 public slots:
20     void print_s();
21  
22 private:
23     Ui::MainWindow *ui;
24 };
25  
26 #endif // MAINWINDOW_H
复制代码

四 main.c中的程序不需改动

复制代码
 1 #include "mainwindow.h"
 2 #include <QApplication>
 3  
 4 int main(int argc, char *argv[])
 5 {
 6     QApplication a(argc, argv);
 7     MainWindow w;
 8     w.show();
 9  
10     return a.exec();
11 }
复制代码

五 在mainwindow.c中编写槽函数及连接

复制代码
 1 #include "mainwindow.h"
 2 #include "ui_mainwindow.h"
 3  
 4 MainWindow::MainWindow(QWidget *parent) :
 5     QMainWindow(parent),
 6     ui(new Ui::MainWindow)
 7 {
 8     ui->setupUi(this);
 9     connect(ui->comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(print_s()));
10 }
11  
12 MainWindow::~MainWindow()
13 {
14     delete ui;
15 }
16  
17 void MainWindow::print_s()
18 {
19     if(ui->comboBox->currentIndex()==0) ui->lineEdit->setText("小振国");
20     else if(ui->comboBox->currentIndex()==1) ui->lineEdit->setText("中振国");
21     else if(ui->comboBox->currentIndex()==2) ui->lineEdit->setText("大振国");
22     else if(ui->comboBox->currentIndex()==3) ui->lineEdit->setText("老振国");
23     else if(ui->comboBox->currentIndex()==4) ui->lineEdit->setText("死振国");
24     else ui->lineEdit->setText("振国");
25 }
复制代码

 

posted on   一杯清酒邀明月  阅读(2479)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示