Results 1 to 7 of 7

Thread: How to use slots in the namespace class

  1. #1
    Join Date
    Nov 2014
    Posts
    54
    Thanks
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default How to use slots in the namespace class

    Hi,

    I am trying to use the slots in a class that is define by using the word namespace in the Qt Creator but it is showing an error "Needs an declaration"
    Is it possible to do so the code that i have written is

    Qt Code:
    1. namespace CCentralImply
    2. {
    3. void func();
    4. void func_one();
    5.  
    6. private slots: //At this Line it shows error [B]expected declaration[/B]
    7. slot_name();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Thanks & regards,
    Rohith.G
    Last edited by gunturrohith; 7th December 2015 at 10:34.

  2. #2
    Join Date
    Feb 2015
    Posts
    22
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to use slots in the namespace class

    Declare using namespace CCentralImply Where ever u want to access namespace modules....

  3. #3
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to use slots in the namespace class

    Namespaces are not classes so they cannot have slots.

  4. #4
    Join Date
    Feb 2015
    Posts
    22
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to use slots in the namespace class

    Y ur Declaring Slots...?

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use slots in the namespace class

    Quote Originally Posted by Vikram.Saralaya View Post
    Namespaces are not classes so they cannot have slots.
    Exactly.

    Slots can only be declared in QObject derived classes.

    However, Qt5's function pointer based connect() can connect to functions that are not slots.

    Cheers,
    _

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to use slots in the namespace class

    However, Qt5's function pointer based connect() can connect to functions that are not slots.
    In addition, there are versions of this connect() that do not require a QObject receiver pointer. From the docs for QObject::connect():

    Qt Code:
    1. void someFunction();
    2. QPushButton *button = new QPushButton;
    3. QObject::connect(button, &QPushButton::clicked, someFunction);
    To copy to clipboard, switch view to plain text mode 

    So potentially if the code in the original post was cleaned up to proper C++ syntax, then the "someFunction" above could be prefaced by the namespace.

  7. The following user says thank you to d_stranz for this useful post:

    anda_skoa (7th December 2015)

  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use slots in the namespace class

    Quote Originally Posted by d_stranz View Post
    In addition, there are versions of this connect() that do not require a QObject receiver pointer.
    Yes, indeed!

    I thought that would be kind of implicit by me writing "function" instead of "method" but it made sense to point this out explicitly

    Cheers,
    _

Similar Threads

  1. “Pass” slots from class to class
    By bmn in forum Qt Programming
    Replies: 1
    Last Post: 3rd October 2015, 00:17
  2. Replies: 2
    Last Post: 26th July 2015, 15:38
  3. How to avoid "class namespace" repetition?
    By arcull in forum General Programming
    Replies: 13
    Last Post: 3rd July 2015, 07:07
  4. Replies: 0
    Last Post: 3rd July 2014, 16:48
  5. Access a class without using Signals/Slots
    By impeteperry in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2010, 11:14

Tags for this Thread

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.