zoukankan      html  css  js  c++  java
  • 2.QT字符串及一些基本操作

    • mainwindow.h
       1 #ifndef MAINWINDOW_H
       2 #define MAINWINDOW_H
       3 
       4 #include <QMainWindow>
       5 
       6 namespace Ui {
       7 class MainWindow;
       8 }
       9 
      10 class MainWindow : public QMainWindow
      11 {
      12     Q_OBJECT
      13 
      14 public:
      15     explicit MainWindow(QWidget *parent = 0);
      16     ~MainWindow();
      17 
      18 private slots:
      19     void on_pushButton_clicked();
      20 
      21     void on_pushButton_2_clicked();
      22 
      23 private:
      24     Ui::MainWindow *ui;
      25 };
      26 
      27 #endif // MAINWINDOW_H
    • mainwindow.cpp
       1 #include "mainwindow.h"
       2 #include "ui_mainwindow.h"
       3 #include <QDebug>
       4 
       5 MainWindow::MainWindow(QWidget *parent) :
       6     QMainWindow(parent),
       7     ui(new Ui::MainWindow)
       8 {
       9     ui->setupUi(this);
      10 }
      11 
      12 MainWindow::~MainWindow()
      13 {
      14     delete ui;
      15 }
      16 
      17 void MainWindow::on_pushButton_clicked()
      18 {
      19     QString qstr1;
      20     QString qstr2;
      21     qstr1 = ui->lineEdit->text();
      22     qstr2 = ui->lineEdit_2->text();
      23     QString qstr3 ;
      24    // qstr3 = qstr1 + qstr2
      25     qstr3.sprintf("%s%d%s","123",45,"abc");
      26     qDebug() << qstr3 << endl;
      27     ui->textEdit->setText(qstr3);
      28 }
      29 
      30 void MainWindow::on_pushButton_2_clicked()
      31 {
      32     QString qstr3=QString("%1 is %2").arg("hello").arg(123);
      33     ui->textEdit->setText(qstr3);
      34 }
  • 相关阅读:
    5. 图 (算法和数据结构笔记)
    4. 树与二叉树 (算法和数据结构笔记)
    Go第八篇之包的使用
    Go第七篇之规范的接口
    Go第六篇之结构体剖析
    Go第三篇之大话容器
    Go第一篇之轻松入门
    Go第四篇之流程控制
    C简介与环境配置
    程序结构与基本语法
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8733521.html
Copyright © 2011-2022 走看看