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.
  • S Offline
    S Offline
    shree_121
    wrote on 21 Nov 2018, 03:24 last edited by
    #1

    By passing value in function i get unsigned char value in varible now i want print it in lineEdit
    but when i use
    ui->lineEdit_1->setText(QString::number(variable name);
    it gives error as call of overloaded 'number(unsigned char[33])' is ambiguous.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 21 Nov 2018, 04:15 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 21 Nov 2018, 06:10 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 1 Reply Last reply 21 Nov 2018, 06:18
        0
        • S shree_121
          21 Nov 2018, 06:10

          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 Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 21 Nov 2018, 06:18 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
          • D Offline
            D Offline
            dheerendra
            Qt Champions 2022
            wrote on 21 Nov 2018, 06:41 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 21 Nov 2018, 07:21 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?

              M 1 Reply Last reply 21 Nov 2018, 07:27
              0
              • S Offline
                S Offline
                shree_121
                wrote on 21 Nov 2018, 07:25 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
                  21 Nov 2018, 07:21

                  @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?

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 21 Nov 2018, 07:27 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 21 Nov 2018, 07:42 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?

                    M 1 Reply Last reply 21 Nov 2018, 07:54
                    0
                    • S shree_121
                      21 Nov 2018, 07:42

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

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 21 Nov 2018, 07:54 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 21 Nov 2018, 08:22 last edited by
                        #11

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

                        1 Reply Last reply
                        0

                        1/11

                        21 Nov 2018, 03:24

                        • Login

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