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. How to convert a qstring to hexadecimal
Forum Updated to NodeBB v4.3 + New Features

How to convert a qstring to hexadecimal

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 3.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.
  • M Offline
    M Offline
    Morado
    wrote on last edited by
    #1

    I am developing an interface where it is necessary to add a value in hexadecimal by means of a QLineEdit, I already have that part including the saving of the data, but I do it in String, I want to know how to save it in herxadecimal, preserving the format, for example, if I write in the QLineEdit: A2 I want to save it in a variable in that same format but in hexadecimal. I don't know if I'm clear, if someone understands what I want to do, can they help me please
    Somthing like this.
    This is a QLineEdit
    ![alt text]f6f62ef6-2adc-4234-b0ed-717603d8411c-image.png
    I want sonthig like this![alt text]46ace04c-6d93-4e13-a19a-6a4a0b347307-image.png (image url)

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Hex is a representation and not a basic true value so you cant really save it a variable as hex.
      but you can convert a string between hex and decimal like this

      QString str = "FF";
      bool ok;
      int hex = str.toInt(&ok, 16);     
      int dec = str.toInt(&ok, 10);    
      
      M 1 Reply Last reply
      3
      • mrjjM mrjj

        Hi
        Hex is a representation and not a basic true value so you cant really save it a variable as hex.
        but you can convert a string between hex and decimal like this

        QString str = "FF";
        bool ok;
        int hex = str.toInt(&ok, 16);     
        int dec = str.toInt(&ok, 10);    
        
        M Offline
        M Offline
        Morado
        wrote on last edited by
        #3

        @mrjj Hi thanks
        Coul you help me, i want to print this value on SerialPort but need to a on hex, how can i do it??

        mrjjM 1 Reply Last reply
        0
        • M Morado

          @mrjj Hi thanks
          Coul you help me, i want to print this value on SerialPort but need to a on hex, how can i do it??

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Morado
          You can use a Qbytearray and send that
          QByteArray array = QByteArray::fromHex( ui->xtxtAdress->text());
          serial.write(array);

          M 1 Reply Last reply
          3
          • mrjjM mrjj

            @Morado
            You can use a Qbytearray and send that
            QByteArray array = QByteArray::fromHex( ui->xtxtAdress->text());
            serial.write(array);

            M Offline
            M Offline
            Morado
            wrote on last edited by
            #5

            @mrjj
            Thanks very much!
            It helped me a lot.

            1 Reply Last reply
            1

            • Login

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