Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] Conversion from ascci to char in QML

[SOLVED] Conversion from ascci to char in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
26 Posts 2 Posters 12.1k Views
  • 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.
  • P Offline
    P Offline
    Pradeep Kumar
    wrote on 17 Jun 2015, 06:39 last edited by Pradeep Kumar 7 May 2015, 16:07
    #1

    Hello ,

    I have Text Input and virtual Keyboard, i want value to be entered in text input, but im getting ascii values of (letters,numbers) in text inout when i press the letters, numbers in keyboard, so i want same letter to be entered in text input as in keyboard, ex: if i click Letter "P","p" i need to get Letter "P","p" in my text input,

    so please help me guys.

    Pradeep Kumar
    Qt,QML Developer

    P 1 Reply Last reply 17 Jun 2015, 06:48
    0
    • P Pradeep Kumar
      17 Jun 2015, 06:39

      Hello ,

      I have Text Input and virtual Keyboard, i want value to be entered in text input, but im getting ascii values of (letters,numbers) in text inout when i press the letters, numbers in keyboard, so i want same letter to be entered in text input as in keyboard, ex: if i click Letter "P","p" i need to get Letter "P","p" in my text input,

      so please help me guys.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 17 Jun 2015, 06:48 last edited by
      #2

      Hi @Pradeep-Kumar.M,
      Use String.fromCharCode to convert code to character and then use insert to add that character to TextInput.

      157

      P 2 Replies Last reply 17 Jun 2015, 06:59
      1
      • P p3c0
        17 Jun 2015, 06:48

        Hi @Pradeep-Kumar.M,
        Use String.fromCharCode to convert code to character and then use insert to add that character to TextInput.

        P Offline
        P Offline
        Pradeep Kumar
        wrote on 17 Jun 2015, 06:59 last edited by
        #3

        @p3c0

        Thank you it worked,,

        but when i press caps lock depending on capital "P" or small "p", it has to print,
        but for caps or small im getting "P" itself

        my code:

        Keys.onPressed:
        {

                if(event.key === Qt.Key_P)
                {
                    console.log("zero is pressed"+String.fromCharCode(Qt.Key_P));
                    textin.insert(0,String.fromCharCode(Qt.Key_P))
                }
            }
        

        textin is id for textinput;
        help me

        Pradeep Kumar
        Qt,QML Developer

        P 2 Replies Last reply 17 Jun 2015, 07:18
        0
        • P Pradeep Kumar
          17 Jun 2015, 06:59

          @p3c0

          Thank you it worked,,

          but when i press caps lock depending on capital "P" or small "p", it has to print,
          but for caps or small im getting "P" itself

          my code:

          Keys.onPressed:
          {

                  if(event.key === Qt.Key_P)
                  {
                      console.log("zero is pressed"+String.fromCharCode(Qt.Key_P));
                      textin.insert(0,String.fromCharCode(Qt.Key_P))
                  }
              }
          

          textin is id for textinput;
          help me

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 17 Jun 2015, 07:18 last edited by
          #4

          @Pradeep-Kumar.M Because it doesn't distinguish between them. Here's more info. You will need to use event.text as described in combination with modifiers I guess.

          157

          P 1 Reply Last reply 17 Jun 2015, 07:39
          0
          • P Pradeep Kumar
            17 Jun 2015, 06:59

            @p3c0

            Thank you it worked,,

            but when i press caps lock depending on capital "P" or small "p", it has to print,
            but for caps or small im getting "P" itself

            my code:

            Keys.onPressed:
            {

                    if(event.key === Qt.Key_P)
                    {
                        console.log("zero is pressed"+String.fromCharCode(Qt.Key_P));
                        textin.insert(0,String.fromCharCode(Qt.Key_P))
                    }
                }
            

            textin is id for textinput;
            help me

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 17 Jun 2015, 07:23 last edited by
            #5

            @Pradeep-Kumar.M That being said you don't need conversion at all. Just use event.text for getting exact character and then insert. Just watch out for other key press (like shift or caps lock) which you will have to ignore.

            157

            P 1 Reply Last reply 17 Jun 2015, 07:34
            0
            • P p3c0
              17 Jun 2015, 07:23

              @Pradeep-Kumar.M That being said you don't need conversion at all. Just use event.text for getting exact character and then insert. Just watch out for other key press (like shift or caps lock) which you will have to ignore.

              P Offline
              P Offline
              Pradeep Kumar
              wrote on 17 Jun 2015, 07:34 last edited by
              #6

              @p3c0
              Keys.onPressed:
              {

                      if(event.text)
                      {
                          console.log("zero is pressed");
              
                          textin.insert(0,String.fromCharCode(Keys))
                      }
                  }
              

              is this code k,
              because when i press any keys its getting printed in application output

              but i need in text input.

              Pradeep Kumar
              Qt,QML Developer

              P 1 Reply Last reply 17 Jun 2015, 07:37
              0
              • P Pradeep Kumar
                17 Jun 2015, 07:34

                @p3c0
                Keys.onPressed:
                {

                        if(event.text)
                        {
                            console.log("zero is pressed");
                
                            textin.insert(0,String.fromCharCode(Keys))
                        }
                    }
                

                is this code k,
                because when i press any keys its getting printed in application output

                but i need in text input.

                P Offline
                P Offline
                p3c0
                Moderators
                wrote on 17 Jun 2015, 07:37 last edited by
                #7

                @Pradeep-Kumar.M No conversion required now. Try

                Keys.onPressed:
                {
                    textin.insert(0,event.text)
                }
                

                157

                1 Reply Last reply
                0
                • P p3c0
                  17 Jun 2015, 07:18

                  @Pradeep-Kumar.M Because it doesn't distinguish between them. Here's more info. You will need to use event.text as described in combination with modifiers I guess.

                  P Offline
                  P Offline
                  Pradeep Kumar
                  wrote on 17 Jun 2015, 07:39 last edited by
                  #8

                  @p3c0

                  its working fine, thank u for that,
                  but in text input, its not appending, its getting from right to left, i want from left to right.

                  Pradeep Kumar
                  Qt,QML Developer

                  P 1 Reply Last reply 17 Jun 2015, 07:44
                  0
                  • P Pradeep Kumar
                    17 Jun 2015, 07:39

                    @p3c0

                    its working fine, thank u for that,
                    but in text input, its not appending, its getting from right to left, i want from left to right.

                    P Offline
                    P Offline
                    p3c0
                    Moderators
                    wrote on 17 Jun 2015, 07:44 last edited by
                    #9

                    @Pradeep-Kumar.M Are you using Arabic language or Arabic locale ? In that case it will be aligned to right side.

                    157

                    P 1 Reply Last reply 17 Jun 2015, 07:47
                    0
                    • P p3c0
                      17 Jun 2015, 07:44

                      @Pradeep-Kumar.M Are you using Arabic language or Arabic locale ? In that case it will be aligned to right side.

                      P Offline
                      P Offline
                      Pradeep Kumar
                      wrote on 17 Jun 2015, 07:47 last edited by
                      #10

                      @p3c0

                      no, in text input its printing, which ever key is pressed, but not in appending fashion

                      ex: if i press 1234567890abcdefgh

                      its printing in text input as hgfedcba0987654321

                      i want in 1234567890abcdefgh

                      Pradeep Kumar
                      Qt,QML Developer

                      P 1 Reply Last reply 17 Jun 2015, 07:48
                      0
                      • P Pradeep Kumar
                        17 Jun 2015, 07:47

                        @p3c0

                        no, in text input its printing, which ever key is pressed, but not in appending fashion

                        ex: if i press 1234567890abcdefgh

                        its printing in text input as hgfedcba0987654321

                        i want in 1234567890abcdefgh

                        P Offline
                        P Offline
                        p3c0
                        Moderators
                        wrote on 17 Jun 2015, 07:48 last edited by
                        #11

                        @Pradeep-Kumar.M Ofcourse it will. You are inserting every new character at 0'th position.

                        157

                        1 Reply Last reply
                        1
                        • P p3c0
                          17 Jun 2015, 06:48

                          Hi @Pradeep-Kumar.M,
                          Use String.fromCharCode to convert code to character and then use insert to add that character to TextInput.

                          P Offline
                          P Offline
                          Pradeep Kumar
                          wrote on 17 Jun 2015, 07:50 last edited by
                          #12

                          @p3c0

                          so what to do if i want in appending fashion of letters, numbers, any other keys from keyboard, to text input

                          Pradeep Kumar
                          Qt,QML Developer

                          P 1 Reply Last reply 17 Jun 2015, 07:52
                          0
                          • P Pradeep Kumar
                            17 Jun 2015, 07:50

                            @p3c0

                            so what to do if i want in appending fashion of letters, numbers, any other keys from keyboard, to text input

                            P Offline
                            P Offline
                            p3c0
                            Moderators
                            wrote on 17 Jun 2015, 07:52 last edited by
                            #13

                            @Pradeep-Kumar.M Get the new index position from TextInput. You want it to append it at the end so length should give you the last index. Insert it there

                            textin.insert(textin.length,event.text)
                            

                            157

                            P 1 Reply Last reply 17 Jun 2015, 07:55
                            1
                            • P p3c0
                              17 Jun 2015, 07:52

                              @Pradeep-Kumar.M Get the new index position from TextInput. You want it to append it at the end so length should give you the last index. Insert it there

                              textin.insert(textin.length,event.text)
                              
                              P Offline
                              P Offline
                              Pradeep Kumar
                              wrote on 17 Jun 2015, 07:55 last edited by
                              #14

                              @p3c0

                              thank you, it worked.

                              Pradeep Kumar
                              Qt,QML Developer

                              P 1 Reply Last reply 17 Jun 2015, 07:56
                              0
                              • P Pradeep Kumar
                                17 Jun 2015, 07:55

                                @p3c0

                                thank you, it worked.

                                P Offline
                                P Offline
                                p3c0
                                Moderators
                                wrote on 17 Jun 2015, 07:56 last edited by
                                #15

                                @Pradeep-Kumar.M You're Welcome :)

                                157

                                P 1 Reply Last reply 17 Jun 2015, 08:07
                                1
                                • P p3c0
                                  17 Jun 2015, 07:56

                                  @Pradeep-Kumar.M You're Welcome :)

                                  P Offline
                                  P Offline
                                  Pradeep Kumar
                                  wrote on 17 Jun 2015, 08:07 last edited by
                                  #16

                                  @p3c0

                                  one more question

                                  i tries Qt Integration

                                  here is ex: of main.cpp

                                  QQmlApplicationEngine engine;
                                  engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                                  QObject *topLevel = engine.rootObjects().value(0);
                                  QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
                                  window->dumpObjectTree();
                                  QQuickWindow *window1 = topLevel->findChild<QQuickWindow * >(objectname);

                                  can i have QQMLContext, QQMLComponent & QQMLEngine,
                                  if so
                                  can u provide code of it, along with component item.

                                  Pradeep Kumar
                                  Qt,QML Developer

                                  P 1 Reply Last reply 17 Jun 2015, 08:11
                                  0
                                  • P Pradeep Kumar
                                    17 Jun 2015, 08:07

                                    @p3c0

                                    one more question

                                    i tries Qt Integration

                                    here is ex: of main.cpp

                                    QQmlApplicationEngine engine;
                                    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                                    QObject *topLevel = engine.rootObjects().value(0);
                                    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
                                    window->dumpObjectTree();
                                    QQuickWindow *window1 = topLevel->findChild<QQuickWindow * >(objectname);

                                    can i have QQMLContext, QQMLComponent & QQMLEngine,
                                    if so
                                    can u provide code of it, along with component item.

                                    P Offline
                                    P Offline
                                    p3c0
                                    Moderators
                                    wrote on 17 Jun 2015, 08:11 last edited by
                                    #17

                                    @Pradeep-Kumar.M Do you mean an example ?

                                    157

                                    P 1 Reply Last reply 17 Jun 2015, 08:12
                                    0
                                    • P p3c0
                                      17 Jun 2015, 08:11

                                      @Pradeep-Kumar.M Do you mean an example ?

                                      P Offline
                                      P Offline
                                      Pradeep Kumar
                                      wrote on 17 Jun 2015, 08:12 last edited by
                                      #18

                                      @p3c0

                                      yeah but
                                      to replace the lines above which i sent in previous post

                                      Pradeep Kumar
                                      Qt,QML Developer

                                      P 1 Reply Last reply 17 Jun 2015, 08:14
                                      0
                                      • P Pradeep Kumar
                                        17 Jun 2015, 08:12

                                        @p3c0

                                        yeah but
                                        to replace the lines above which i sent in previous post

                                        P Offline
                                        P Offline
                                        p3c0
                                        Moderators
                                        wrote on 17 Jun 2015, 08:14 last edited by
                                        #19

                                        @Pradeep-Kumar.M Here's an example.

                                        157

                                        P 1 Reply Last reply 17 Jun 2015, 08:17
                                        1
                                        • P p3c0
                                          17 Jun 2015, 08:14

                                          @Pradeep-Kumar.M Here's an example.

                                          P Offline
                                          P Offline
                                          Pradeep Kumar
                                          wrote on 17 Jun 2015, 08:17 last edited by
                                          #20

                                          @p3c0

                                          for wat exactly setcontextproperty is used

                                          Pradeep Kumar
                                          Qt,QML Developer

                                          P 1 Reply Last reply 17 Jun 2015, 08:19
                                          0

                                          6/26

                                          17 Jun 2015, 07:34

                                          topic:navigator.unread, 20
                                          • Login

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