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 print variable unsigned char value in QLineEdit
Forum Updated to NodeBB v4.3 + New Features

how to print variable unsigned char value in QLineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 2.7k 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #2

    QString value(name). // name is your unsigned char string
    ui->lineEdit_1.setText(value).

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shree_121
      wrote on last edited by
      #3

      Thanks @dheerendra,
      In my case i dont't know the string which unsigned char hold because unsigned char get it from function and i want to print in lineEdit to see that so how can i do it?

      J.HilkJ 1 Reply Last reply
      0
      • S shree_121

        Thanks @dheerendra,
        In my case i dont't know the string which unsigned char hold because unsigned char get it from function and i want to print in lineEdit to see that so how can i do it?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #4

        @shree_121 you can simply pass setText the pointer to the char array, as long as it's 0 terminated it will implicitly convert it to a string.

        this for example works fine:

        ui->lineEdit_1->setText(Q_FUNC_INFO);
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #5

          As @J-Hilk already suggested try directly. If not give your complete sample. We will help you. Your code does not give the what you are getting.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shree_121
            wrote on last edited by
            #6

            @J.Hilk @dheerendra thanks, here is my program as
            GTB_INFO stuGtbInfo; //from library
            iRet = LNB_GTB_info(&stuGtbInfo); //library function
            ui->lineEdit->setText(stuGtbInfo); //is it correct or need to define pointer separately?

            mrjjM 1 Reply Last reply
            0
            • S Offline
              S Offline
              shree_121
              wrote on last edited by
              #7

              some more information..
              &stuGtbInfo will return three differnt unsigned char array as stuGtbInfo.strubmodel, stuGtbInfo.strubversion, stuGtbInfo.strubrevision.

              1 Reply Last reply
              0
              • S shree_121

                @J.Hilk @dheerendra thanks, here is my program as
                GTB_INFO stuGtbInfo; //from library
                iRet = LNB_GTB_info(&stuGtbInfo); //library function
                ui->lineEdit->setText(stuGtbInfo); //is it correct or need to define pointer separately?

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

                @shree_121
                So it would be
                ui->lineEdit->setText(stuGtbInfo.strubmodel);

                if strubmodel is the char *
                do you want all 3 char* into one string ?
                to display?

                like
                QString model(stuGtbInfo.strubmodel);
                QString version(stuGtbInfo.strubversion);
                QString rev(stuGtbInfo.strubrevision);

                ui->lineEdit->setText( model+"|"+version+"|"+rev );

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  shree_121
                  wrote on last edited by
                  #9

                  @mrjj
                  ui->lineEdit->setText(stuGtbInfo.strubmodel);
                  gives me error as invalid user-defined conversion from 'unsigned char[33]' to 'const QString&'
                  what's wrong?

                  mrjjM 1 Reply Last reply
                  0
                  • S shree_121

                    @mrjj
                    ui->lineEdit->setText(stuGtbInfo.strubmodel);
                    gives me error as invalid user-defined conversion from 'unsigned char[33]' to 'const QString&'
                    what's wrong?

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

                    @shree_121
                    That it cant make a QString from stuGtbInfo.strubmodel.
                    Its unsigned char which is a bit odd for a string.
                    try
                    ui->lineEdit->setText(reinterpret_cast<const char *>((stuGtbInfo.strubmodel));

                    1 Reply Last reply
                    2
                    • S Offline
                      S Offline
                      shree_121
                      wrote on last edited by
                      #11

                      @mrjj thanks a lott..it worked for me.

                      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