Qt World Summit: Register Today!

Can I use QSerialPort class on C not C++?

  • if it can, how to?

  • Yes you can.
    You need to create a wrapper C library that will hide all C++ and provide C interface to the classes. You need to create an init() function that will initialize Qt and then provide openSerial(), readSerial(), closeSerial(), and whatever other functions you need.
    Don't forget to use
    extern "C" {
    around your C functions.

  • Thank you andreyc,

    But I want to know method to use Qt library on C.

    When I use your recommended method, it works well?

  • Qt Champions 2017

    Use QLibrary class

  • @Dheerendra: You should read the question and not just answer to collect points.

  • Qt Champions 2017

    hmm. Thank your comment. Sorry if you have misinterpreted the question. I took the question other way around.

    Now coming to points does not help me any way. I'm not here for points. I'm spending my personal time here without any gains. I here to help the people with my knowledge. If you have admin capability request you to set all my points to zero.

    I'm here to get my Qt knowledge enlightened. Nothing more than.

  • @Dheerendra: It's ok. It was a bit hard from me, sorry for that. If you got your knowledge "enlightened" you hit the target. Have a nice day.

  • [quote author="jaeheon" date="1404960344"]But I want to know method to use Qt library on C.[/quote]
    Out of curiosity, why do you need to use Qt in C project?

    [quote]When I use your recommended method, it works well?[/quote]
    It should work. There is nothing special about Qt here. It is a way to provide a C API to C++ library. I used it but not with Qt.
    I would not recommend to provide full Qt API through C API only a part that you need for your project.

Log in to reply