Nominate our 2022 Qt Champions!

QString to QKeyEvent

  • 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".

  • Moderators

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

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



    Inside the "eventFilter" function , I am reading the namedpipe using native linux approach
    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];
        // First open in read only and read
        fd1 = open(myfifo,O_RDONLY);
        read(fd1, str1, 80);
        // Print the read string and close
        // 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);
    return 0;


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

  • Moderators

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

  • 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

Log in to reply