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. Expand Activeqt comapp example to separate classes from main.cpp
Forum Updated to NodeBB v4.3 + New Features

Expand Activeqt comapp example to separate classes from main.cpp

Scheduled Pinned Locked Moved Unsolved General and Desktop
forum
6 Posts 2 Posters 68 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.
  • A Offline
    A Offline
    AliQT
    wrote last edited by
    #1

    Hi
    I am trying to use the ActiveQT comapp example in the QT installation examples folder as the basis for finding out how to add ActiveX visibility to an existing QT application, ie turn it into an out of process com server. I am a novice when it comes to QT and c++ but can understand it and make simple alterations to existing code. The initial problem I am having is separating the three classes in the example main.cpp file (ie Application, Document and DocumentList,) into separate .cpp and .h files. I think this is necessary before trying to expand to the multiple classes I will need going forward, as it is impractical to put them all into one .cpp file without headers. The issues I ge largely seem to do with circular dependancies between the classes, as eg the DocumentList has a parent of the Application class. I know there many articles giving advice on how to get around such circular references to be found on the web, but I have tried so many times to use them, without success, that I am desperate. It would be so helpful if someone with both QT and c++ experience could seperate the classes to eg Application.cpp/.h DocumentList.cpp/.h Document.cpp/.h with the example still compiling/ working. Is there anyone who would do this for me? Payment would be available if required.
    Thanks

    JonBJ 1 Reply Last reply
    0
    • A AliQT

      Hi
      I am trying to use the ActiveQT comapp example in the QT installation examples folder as the basis for finding out how to add ActiveX visibility to an existing QT application, ie turn it into an out of process com server. I am a novice when it comes to QT and c++ but can understand it and make simple alterations to existing code. The initial problem I am having is separating the three classes in the example main.cpp file (ie Application, Document and DocumentList,) into separate .cpp and .h files. I think this is necessary before trying to expand to the multiple classes I will need going forward, as it is impractical to put them all into one .cpp file without headers. The issues I ge largely seem to do with circular dependancies between the classes, as eg the DocumentList has a parent of the Application class. I know there many articles giving advice on how to get around such circular references to be found on the web, but I have tried so many times to use them, without success, that I am desperate. It would be so helpful if someone with both QT and c++ experience could seperate the classes to eg Application.cpp/.h DocumentList.cpp/.h Document.cpp/.h with the example still compiling/ working. Is there anyone who would do this for me? Payment would be available if required.
      Thanks

      JonBJ Online
      JonBJ Online
      JonB
      wrote last edited by JonB
      #2

      @AliQT said in Expand Activeqt comapp example to separate classes from main.cpp:

      The issues I ge largely seem to do with circular dependancies between the classes, as eg the DocumentList has a parent of the Application class.

      The classes use pointers to each other. They do not need to see the definition of the other classes, only that they exist. For example if DocumentList is in a separate file from Application it does not need to #include "application.h", you only need to write

      class Application;
      

      above the class DocumentList definition and that allows it to have e.g. explicit DocumentList(Application *application);.

      Note how the main.cpp itself already has

      class Application;
      class DocumentList;
      

      near the top.

      I don't see any circular dependencies there, the classes should be splittable into separate files so long as they only reference each other via pointers. You only need the other class definition if you dereference the pointer, which I don't see going on.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        AliQT
        wrote last edited by
        #3

        Hi Jon, thanks for the swift reply.
        I've split the classes as I think you're suggesting, but am getting issues shown in the below screenprint, ie eg 'use of undefined type ''DocumentList' in application.cpp. I've added the code for the claases and remnant of main.cpp below.

        issues.png

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AliQT
          wrote last edited by
          #4

          The forum doesen't seem to allow posting of code. Do you know how I can get the code to the forum or yourself?

          codeisspam.png

          1 Reply Last reply
          0
          • JonBJ Online
            JonBJ Online
            JonB
            wrote last edited by JonB
            #5

            @AliQT
            I'm afraid the Akismet post checker thing seems to ban a lot of legitimate stuff, especially with large code blocks. Really someone ought try to do something about this, you are not the first person to fall foul. I think I can see you have tried to enclose your code inside a pair of ``` lines, which is just the right thing to do but it still rejects it anyway.

            It's hard to see from the two screenshots just what you have and what is wrong. A whole bunch of consequential errors in the first shot, probably depends on what the cause of the first error is. For the second shot, on the one hand I cannot spot what is wrong with the QTimer::singleShot() call.

            I will have a go now at copying that sample and dividing it into Application/DocumentList/Document module files for you. Will let you know when done and we will find some way of getting it to you.

            1 Reply Last reply
            0
            • JonBJ Online
              JonBJ Online
              JonB
              wrote last edited by JonB
              #6

              @AliQT
              OK, I have done a version which compiles, splitting all 3 classes into their own source files.

              It's a .zip file containing just the sources. I have uploaded to a free site where I understand the link remains available for a week. It is https://limewire.com/d/sFtIk#JbakOrsCmy . I created/uploaded it via https://file.io . So far as I understand this a common site and is all safe & legit, but obviously access at your own risk.

              There are indeed issues which affect the normally-more-straightforward processes of splitting C++ classes into separate files. These were due to Qt features including Q_PROPERTY and QScopedPointer. I commented these where the problems arose and put in my replacement. I believe the functionality is the same. I agree there are tricky issues here. If what I have done is indeed required then I agree it would not be easy for a beginner.

              I do not do Qt under Windows so I cannot actually compile, let alone test, the stuff to do with QAxObject (you do realise that is Windows only, right?). I have commented out all the lines which which can only compile under Windows, you can put them back in.

              You will have to test with COM/ActiveX --- like the VB example they give on the example page --- to verify whether the couple of changes I was forced to make lead to any problems.

              I may return to this to understand whether I could have made it work without having to make the changes I did.

              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