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. C++ with C standards
QtWS25 Last Chance

C++ with C standards

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.2k 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.
  • F Offline
    F Offline
    fykos
    wrote on last edited by
    #1

    Hello guys,

    I was building a gui for a simple program a friend made in C++ but I just found out that his program is a cpp file but it is written with the C standards, this means no object orientation and classes.

    I have completely stuck, how can I proceed from now on? I was thinking to convert the program in actual c++ with objects and classes but the whole project is already quite bug with many headers and other .cpp files.

    Another solution I thought is to use the gtk platform to build the gui.

    Any suggestions?

    1 Reply Last reply
    0
    • U Offline
      U Offline
      unai_i
      wrote on last edited by
      #2

      Hi,
      It depends what parts are present in your friend's project. If the project only deals with data and has not graphical interface yet, you can just make a C++ wrapper of the useful parts or export them in a library for your graphical interface. If it already has a GUI, you will have to port it to Qt if you want a uniform visual experience.

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

        Hey unai_i,

        That sounds very good news. The project mostly deals with data and uses ncurses to make a simple interface. Basically, the useful parts I want from the code are 3 char buffers that have data that I need to display to the gui.

        Do you have any resource where I can check how to make a wrapper or how to export stuff to a library?

        1 Reply Last reply
        0
        • U Offline
          U Offline
          unai_i
          wrote on last edited by
          #4

          Basically, if all you need is those 3 char buffers you can wrap the code that generates those in a class and expose your data in methods as QByteArrays or use QBuffers if your data is generated continuously. When you have this, build your interface and pass the data you want to show.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fykos
            wrote on last edited by
            #5

            It seems that the extern keyword can work also in this case. What do you think about that?

            1 Reply Last reply
            0
            • U Offline
              U Offline
              unai_i
              wrote on last edited by
              #6

              Of course, there is not a single way to achieve what you want and the extern keyword can be used too. It all depends how you want to expose your data (through a class, function call, signal slot connection, direct variable or reference access, ...).

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Apelsinsaft
                wrote on last edited by
                #7

                To answer your question in a generic way, here's how you could think:

                • What does you friend's code do? It probably consumes (receives) data in some way, and produces data in some way.

                • What would be an interface to this functionality that is convenient to you? If this is a small project, an interface could simply be the declaration of a class. What member functions in the class would make it convenient for you to access the functionality that your friend's code implements?

                • Create a class MyEncapsulationOfMyFriendsCode (actually don't - come up with a better name :)) , with the interface that you like, and then use your friends code in the definition of your class by calling it, like C functions, from your C++ class member functions. Start by writing the declaration (the .h header) and start the implementation once you're reasonably satisfied with the interface.

                If you want more information, you can google "c++ c wrapping" or similar.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  stereomatching
                  wrote on last edited by
                  #8

                  I would wrapped it with some wrappers if and only if I find out I need them(ex : it is no sense to wrapped std::sort, std::find_if and other non OO api by classes).

                  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