Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. QDate全局变量声明的问题
Forum Updated to NodeBB v4.3 + New Features

QDate全局变量声明的问题

Scheduled Pinned Locked Moved Unsolved Chinese
2 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • abuzerA Offline
    abuzerA Offline
    abuzer
    wrote on last edited by
    #1

    我手头上在用Qt做一些工具,用到很多dateedit组件,可是每次都要声明一次变量很麻烦
    比如:
    void MainWindow::on_pushButtonTestDate_clicked()
    {
    QDate A = ui->dateEditA->date();
    QDate B = ui->dateEditB->date();
    // ........some codes
    }

    void MainWindow::on_pushButtonTestDate2_clicked()
    {
    QDate A = ui->dateEditA->date();
    QDate B = ui->dateEditB->date();
    // ........some codes 每次再声明一次很麻烦,有时候多了每个都要声明
    }

    我的问题就是:
    我怎么才能将诸如 QDate A, QDate B 等声明为全局变量?目的是一次声明可以多次用,而不是现在这样每个"void MainWindow::...."里面都要重复声明一次,毫无意义的增加了代码量。

    谢谢高手!

    1 Reply Last reply
    0
    • FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      我想到的方式是把QDate A、QDate B宣告在MainWindow裡面,然後用pointer的方式指向ui->dateEditA->date()、ui->dataEditB()->date()

      如果你只是覺得每次要打ui->dataEdutA->date()、ui->dateEdutB()->date()很長的話,要不要用macro的方式替換成A、B就好

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved