Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

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



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


  • 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