Results 1 to 6 of 6

Thread: Connecting to Undeclared Slots

  1. #1
    Join Date
    Oct 2007
    Posts
    38
    Thanks
    1

    Default Connecting to Undeclared Slots

    Hello,

    I'm starting to get the hang of QT. I found an older tutorial that has really helped me but there are some differences between version 2.3 and 4.3 which need addressing. In version 2.3 (the one my tutorial was written for) you could easily connect slots that didn't already exist in the Designer and then define them later in code. In 4.3 how can you connect slots that aren't preprogrammed in the Designer?

    Another related question: I have a MainWindow form with a menu. The menu has one field called Actions and the Actions menu has one action called: connect.

    When connect is clicked I want to activate my connect socket code. Could someone possibly outline the .h file I'd need for this? I'm confused about the sub-classing involved.

    Here's what I'm thinking:
    Qt Code:
    1. #ifndef MCHAT_H
    2.  
    3. #include "ui_MChat.h"
    4.  
    5. class MChat : public QMainWindow {
    6. Q_OBJECT
    7.  
    8. public:
    9. MChat(QMainWindow *parent = 0);
    10.  
    11. private slots:
    12. /* Somehow tell action_Connect() that it should call this slot
    13.   when activated() is signalling */
    14. virtual void connect();
    15.  
    16.  
    17.  
    18.  
    19. #endif MCHAT_H
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Connecting to Undeclared Slots

    First of all I suggest you don't use "connect" as the name for your method, because it is easy to have a name clash with QObject::connect().

    Here is a link that will describe you how to use Designer created components in your applications: http://doc.trolltech.com/latest/desi...component.html

  3. #3
    Join Date
    Oct 2007
    Posts
    38
    Thanks
    1

    Default Re: Connecting to Undeclared Slots

    Thanks, but I don't see where it talks about connecting slots via the designer in that tutorial.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Connecting to Undeclared Slots

    You can't connect slots via Designer in Qt4. The reference tells you how to declare and use Designer created components in your applications (including how to add slots).

  5. #5
    Join Date
    Oct 2007
    Posts
    38
    Thanks
    1

    Default Re: Connecting to Undeclared Slots

    Ah, okay thanks. (Too bad though...)

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Connecting to Undeclared Slots

    Quote Originally Posted by Dumbledore View Post
    (Too bad though...)
    Not really... You'd have to declare and implement the slot in the subclass anyway. And you can use the auto-connect feature to avoid the need of having to write the connect statement. So in reality this is less work and not more.

Similar Threads

  1. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  2. Qt 4.1.4 plugin QPSQL
    By jcr in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd June 2006, 22:55
  3. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 18th May 2006, 23:28
  4. Connecting signals & slots across different threads
    By jyoti kumar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 12:40
  5. lQtGuid4 error - Compiler setting problem
    By Kapil in forum Installation and Deployment
    Replies: 7
    Last Post: 10th February 2006, 09:30

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.