Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with passing QDateTimeEdit to QString

Problem with passing QDateTimeEdit to QString

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.9k 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.
  • N Offline
    N Offline
    nanohueso
    wrote on last edited by
    #1

    Hi everybody ,im working on a project in wichi i have a QTimeEdit object . So i added a signal slot
    The idea is to send via serial communication the data but first i want to check if the conversion QDateTimeEdit to QString is correctly being made .. but no :S .
    I put a text label (QPlaintTextEdit ) so to print the QDateTimeEdit there and verify that the conversion is right.

    void MainWindow::on_dateTimeEdit_editingFinished()
    {
    QDate aux_date;
    QString str_date;
    QString str_time;
    QTime aux_time;
    aux_date = ui->dateTimeEdit->date();
    aux_date.toString(str_date);
    aux_time = ui->dateTimeEdit->time();
    aux_time.toString(str_time);
    str_date.append(str_time); //ahora tengo todo los datos en el string str_date
    ui->texto_prueba->setPlainText(str_date); // texto_prueba is a QPlaintTextEdit object

    }

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi, you code is wrong.
      @
      str_date = aux_date.toString();
      @

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nanohueso
        wrote on last edited by
        #3

        thank you, i was using the wrong function

        now i have this:

        void MainWindow::on_dateTimeEdit_editingFinished()
        {
        QDate aux_date;

        QTime aux_time;
        
        QString str_date;
        
        QString str_time;
        
        QString format = "dd.MM.yyyy";
        
        int horas,minuts,segundos,tiempo;
        
        aux_date = ui->dateTimeEdit->date();
        
        str_date = aux_date.toString(format);
        

        aux_time = ui->dateTimeEdit->time();

        str_time = aux_time.toString("hh:mm:ss AP");
        

        the conversion of the QDateTimeEdit to QString works perfect.
        I have the str_date in the format of "dd.MM.yyyy" , now i need to have:
        int day = dd;
        int month = MM;
        int year = yyyy;
        the same with the str_time , the format is hh:mm:ss AP :
        int sec = ss;
        int min = mm;
        int hour = hh;
        how can i make that ??
        anyidea on how can i send 'AM' or 'PM' ?

        thanks

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Use QDate and QTime returned form QDateTime::date() and QDateTime::time(). For the AM/PM you can retrieve them using toString.

          Also please, use coding tags around your code, otherwise it makes it very hard to read.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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