Results 1 to 2 of 2

Thread: The application with connected units.

  1. #1
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default The application with connected units.

    Hi!


    1. I need to create GPL the application similar on SCADA.
    2. In it it is necessary to provide possibility of a choice and connection of external units of data gathering.
    3. Data gathering units represent (preliminary) - classes The successor from QThread.
    4. These units should have such interfaces as: (For example)
    - Module. Start ()
    - Module. Stop ()
    - Module. Configure ()
    ....
    Others API
    ....
    5. They should be connected to the application by a choice in the menu of appropriate library with (*.dll/*.so unit.
    6. After the unit is connected to the application done Module. Start (for example) -
    and the unit reads out the configuration and is autonomously started in operation!

    Prompt, how by means of mechanisms QT4 to me correctly to make it?

    I while have thought up to do so: (but I do not know, it is correct so or not)

    interfaces.h

    Qt Code:
    1. #ifndef INTERFACES_H
    2. #define INTERFACES_H
    3.  
    4. class MyModuleInterface
    5. {
    6. public:
    7. virtual ~MyModuleInterface() {}
    8. virtual void MyModuleStart() = 0;
    9. virtual void MyModuleStop() = 0;
    10. };
    11.  
    12. Q_DECLARE_INTERFACE(MyModuleInterface, "mywww.My.MyModuleInterface/1.0")
    13.  
    14. #endif
    To copy to clipboard, switch view to plain text mode 

    myPlug.h

    Qt Code:
    1. #ifndef MYPLUG_H
    2. #define MYPLUG_H
    3.  
    4. #include <QObject>
    5. #include <QThread>
    6.  
    7. #include "../app/interfaces.h"
    8.  
    9. //this my connected module class
    10. class TMyModule : public QThread
    11. {
    12. Q_OBJECT
    13.  
    14. protected:
    15. void run();
    16. /*
    17.  
    18. */
    19. public:
    20. bool mabort;
    21. /*
    22. Here I will add then in public, private various methods of type necessary for me in future:
    23. start, stop, configure, etc
    24. */
    25. };
    26.  
    27. class MyModulePlugin : public QObject,
    28. public MyModuleInterface
    29. {
    30. Q_OBJECT
    31. Q_INTERFACES(MyModuleInterface)
    32.  
    33.  
    34. public:
    35. void MyModuleStart();
    36. void MyModuleStop();
    37. /*
    38. Here I will add then in public, private various methods of type necessary for me in future:
    39. start, stop, configure, etc
    40. */
    41. private:
    42. TMyModule Module;
    43. };
    44.  
    45. #endif
    To copy to clipboard, switch view to plain text mode 

    myPlug.cpp

    Qt Code:
    1. #include <QtGui>
    2. #include "myPlug.h"
    3.  
    4.  
    5. void TMyModule::run()
    6. {
    7. printf("Module is Running \n");
    8. while (!mabort) {
    9. sleep(1);
    10. printf("Run \n");
    11.  
    12. /*
    13.   Here the algorithm of operation of the unit will be purely realised for example
    14.   */
    15. }
    16. printf("Module is Stopped \n");
    17. }
    18.  
    19. void MyModulePlugin::MyModuleStart()
    20. {
    21. Module.mabort = false;
    22. if (!Module.isRunning())
    23. Module.start();
    24. }
    25.  
    26. void MyModulePlugin::MyModuleStop()
    27. {
    28. Module.mabort = true;
    29. }
    30.  
    31. Q_EXPORT_PLUGIN2(mymoduleplugin, MyModulePlugin)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2008
    Posts
    29
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: The application with connected units.

    Prompt, how by means of mechanisms QT4 to me correctly to make it?
    I'm not sure if I correctly understand.. If you ask about possible ways how to design your plugin architecture..

    It seems functional on the first look.. It is questionable if the plugin's main class MyModulePlugin should implement MyModuleInterface or should provide a general factory for on object (or thread) implementing your interface, but it depends.. if you want to have only one interface per plugin, your solution is good.

    If your threads in the plugins need to communicate with each other, you should also consider some communication mechanism. And if they communicate and you provide dynamic attaching and detaching of your plugins, you should also add some locking mechanism to be sure, that plugin is not being detached in the moment somebody is communicating with him..

    everything is question of your needs

Similar Threads

  1. QSkinWindows Classes
    By kernel_panic in forum Qt-based Software
    Replies: 45
    Last Post: 20th April 2010, 12:35
  2. Loading library from application
    By mourad in forum Installation and Deployment
    Replies: 0
    Last Post: 2nd April 2008, 15:10
  3. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37
  4. Replies: 10
    Last Post: 4th December 2006, 05:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.