Results 1 to 7 of 7

Thread: A Design Issue...

  1. #1
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation A Design Issue...

    I have this Design issue with my Qt app.

    Module 1:
    controller.h
    controller.cpp
    controller_main.cpp

    Has 4 buttons.

    //signal slots disabled...just display

    Module 2:
    MyInterface.h
    MyInterface.cpp
    myinterface_main.cpp

    //has signals and slots, w.r.t. the buttons in the interface.

    Has 4 interfaces (i.e 4 MyInterface objects), one for each button (w.r.t. module 1)
    The two modules were created independently, and thus two "main.cpp" files. This helped us test the working independently.

    Now what I am not able to figure out is this:
    Without using aggregation (i.e. declaring MyInterface objects in Controller) how do I activate the signals/slots,
    s.t. when a button is clicked in Module 1, the Corresponding interface designed in module 2 should be invoked.

    ummm I am quite

    I'll appreciate your help

    Thanks

    Nupul

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Design Issue...

    Just connect controller signals to slots of those interfaces.

  3. #3
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Design Issue...

    Quote Originally Posted by nupul
    I have this Design issue with my Qt app.



    The two modules were created independently, and thus two "main.cpp" files. This helped us test the working independently.

    Now what I am not able to figure out is this:
    Without using aggregation (i.e. declaring MyInterface objects in Controller) how do I activate the signals/slots,
    s.t. when a button is clicked in Module 1, the Corresponding interface designed in module 2 should be invoked.

    ummm I am quite

    I'll appreciate your help

    Thanks

    Nupul
    Connect the two objects together in a single main, e.g:

    Qt Code:
    1. // Create objects
    2. Controller* c = new Controller(...);
    3. MyInterface* mi = new MyInterface(...);
    4. ...
    5. // Connect objects together
    6. QObject::connect(c->button1, SIGNAL(clicked()), mi, SLOT(handleButton1Click()));
    7. QObject::connect(c->button2, SIGNAL(clicked()), mi, SLOT(handleButton2Click()));
    8. ...etc.
    To copy to clipboard, switch view to plain text mode 

    Personally I would make the buttons private members of Controller and capture and re-emit their signals from controller, but that's outside the scope of this problem.
    Save yourself some pain. Learn C++ before learning Qt.

  4. The following user says thank you to Chicken Blood Machine for this useful post:

    nupul (3rd May 2006)

  5. #4
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Design Issue...

    Is the case usually handled like the above code snippet? shouldn't there be a different way for such units to be connected...without using aggregation - so as to not strongly couple a system!!

    Nupul

  6. #5
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Design Issue...

    Where do you see aggregation? I don't see any aggregation.
    Save yourself some pain. Learn C++ before learning Qt.

  7. #6
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: A Design Issue...

    Quote Originally Posted by Chicken Blood Machine
    Where do you see aggregation? I don't see any aggregation.
    My mistake...I was referring to aggregation as mentioned in my problem....not in your code - I just mixed two statements into 1

    Personally I would make the buttons private members of Controller and capture and re-emit their signals from controller,
    but that's outside the scope of this problem.
    I don't think it's out of scope. I was hasty in my reply and didn't realise...The buttons of controller are private
    to the class! Thus the above solution (your prev reply), won't work...I will have to do what you quoted!

    Do I need to capture and re-emit a simple signal like clicked() for each of the 4 buttons? How can I use 1 signal and still be able to do the needful? I'd appreciate even a pseudo-code snippet to better understand this implementation

    I feel that your snippet would make the modules highly cohesive - a desirabile trait - I
    just want to confirm this with you guys

    Thanks

    Nupul

  8. #7
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Design Issue...

    Quote Originally Posted by nupul
    Do I need to capture and re-emit a simple signal like clicked() for each of the 4 buttons? How can I use 1 signal and still be able to do the needful? I'd appreciate even a pseudo-code snippet to better understand this implementation
    Generally, you should have a separate signal for each button. Unless the buttons are in a homogenous group and you just want the id/index of the pressed button, then you are better declaring a signal associated with the function of each button.

    Qt Code:
    1. // Interface
    2. class SaleOrderDialog
    3. {
    4. Q_OBJECT
    5. public :
    6. SaleOrderDialog(...);
    7. ...
    8. signals :
    9. void orderItems();
    10. void calculateTotal();
    11. ...
    12. private :
    13. QPushButton* orderButton;
    14. QPushButton* totalButton;
    15. };
    16.  
    17. // Implementation
    18. SaleOrderDialog::SaleOrderDialog(...)
    19. {
    20. ...
    21.  
    22. // Delegate button clicks to public signals
    23. connect(orderButton, SIGNAL(clicked()), SIGNAL(orderItems()));
    24. connect(totalButton, SIGNAL(clicked()), SIGNAL(calculateTotal()));
    25. }
    To copy to clipboard, switch view to plain text mode 

    If you follow my example, you will see that the interface of the dialog, declares signals
    that describe specific functionality provided by the module and expose nothing about the nature of the GUI inside. You are now free to exchange your push buttons for toolbuttons or other widgets, even change the widget signal that you wish to use to initiate the action (for example toggled() instead of clicked()) without changing the objects connected to this one. Use an intermediate slot if you need to emit a signal with more information (i.e. more parameters). Sometimes you can shorten this step if you use a QSignalMapper.

    I hope this addresses your quandaries.
    Save yourself some pain. Learn C++ before learning Qt.

  9. The following user says thank you to Chicken Blood Machine for this useful post:

    nupul (5th May 2006)

Similar Threads

  1. Replies: 3
    Last Post: 5th October 2008, 23:41
  2. QSystemTrayIcon as "main window" design issue
    By nooky59 in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2008, 13:15
  3. qt3 to qt4 - uic issue
    By hvengel in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2007, 02:59
  4. Dialog and code design issue
    By Gopala Krishna in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2006, 17:54
  5. Replies: 5
    Last Post: 22nd September 2006, 08:04

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.