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. QString to QKeyEvent
Qt 6.11 is out! See what's new in the release blog

QString to QKeyEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.2k 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.
  • F Offline
    F Offline
    FVKamlesh
    wrote on last edited by
    #1

    Hello Everyone
    In order to simulate a keyboard , I have created a namedpipe with a writer and reader application. The reader application is able to read the input from the writer application. The captured input in the namedpipe is a string. I have the task to convert the string to QKeyEvent. On conversion to QKeyEvent, I will use the eventFilter function to handle the respective events for the "converted QKeyEvent".

    raven-worxR 1 Reply Last reply
    0
    • F FVKamlesh

      Hello Everyone
      In order to simulate a keyboard , I have created a namedpipe with a writer and reader application. The reader application is able to read the input from the writer application. The captured input in the namedpipe is a string. I have the task to convert the string to QKeyEvent. On conversion to QKeyEvent, I will use the eventFilter function to handle the respective events for the "converted QKeyEvent".

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @FVKamlesh
      see the QKeyEvent constructor and serialize as many properties from the source event as needed and parse them again into a QKeyEvent on the target side.

      But hard to give an actual help, since you didn't ask any question?!

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • F Offline
        F Offline
        FVKamlesh
        wrote on last edited by
        #3

        I followed the steps as you mentioned
        I have a class
        [Code]
        class nativekeyboardfilter: public QObject
        {
        public:
        bool eventFilter(QObject* obj, QEvent* event);

        };

        [/Code]

        Inside the "eventFilter" function , I am reading the namedpipe using native linux approach
        [Code]
        int fd1;
        // FIFO file path
        char * myfifo = "/tmp/myfifo";

        // Creating the named file(FIFO)
        // mkfifo(<pathname>,<permission>)
        mkfifo(myfifo, 0666);
        
        char str1[80], str2[80];
        while(1)
        {
            // First open in read only and read
            fd1 = open(myfifo,O_RDONLY);
            read(fd1, str1, 80);
        
            // Print the read string and close
            printf("User1:%s",str1);
            close(fd1);
        
            // Now open in write mode and write
            // string taken from user.
            fd1 = open(myfifo,O_WRONLY);
            fgets(str2, 80, stdin);
            write(fd1, str2, strlen(str2)+1);
            close(fd1);
        }
        return 0;
        

        }
        [/Code]

        The str1 gets the input from the named pipe, but in this case, the gui application doesnt come up.

        raven-worxR 1 Reply Last reply
        0
        • F FVKamlesh

          I followed the steps as you mentioned
          I have a class
          [Code]
          class nativekeyboardfilter: public QObject
          {
          public:
          bool eventFilter(QObject* obj, QEvent* event);

          };

          [/Code]

          Inside the "eventFilter" function , I am reading the namedpipe using native linux approach
          [Code]
          int fd1;
          // FIFO file path
          char * myfifo = "/tmp/myfifo";

          // Creating the named file(FIFO)
          // mkfifo(<pathname>,<permission>)
          mkfifo(myfifo, 0666);
          
          char str1[80], str2[80];
          while(1)
          {
              // First open in read only and read
              fd1 = open(myfifo,O_RDONLY);
              read(fd1, str1, 80);
          
              // Print the read string and close
              printf("User1:%s",str1);
              close(fd1);
          
              // Now open in write mode and write
              // string taken from user.
              fd1 = open(myfifo,O_WRONLY);
              fgets(str2, 80, stdin);
              write(fd1, str2, strlen(str2)+1);
              close(fd1);
          }
          return 0;
          

          }
          [/Code]

          The str1 gets the input from the named pipe, but in this case, the gui application doesnt come up.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @FVKamlesh said in QString to QKeyEvent:

          Inside the "eventFilter" function , I am reading the namedpipe using native linux approach

          why?!?! why inside the event filter?
          What does the event filter have to do with the named pipe?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • F Offline
            F Offline
            FVKamlesh
            wrote on last edited by
            #5

            After going through the blogs, I understood that I need to

            1. Convert the string coming from the namedpipe to Qevent.

            2. This converted Qevent should be linked to qapplication.postevent

            3. In my application, I will have to connect the "eventfilter" with the above converted Qevent

            Can you help me with the first one

            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