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. How do I write a slot method in main, I want to write this slot method outside of main

How do I write a slot method in main, I want to write this slot method outside of main

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 405 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.
  • C Offline
    C Offline
    canid
    wrote on last edited by
    #1

    How do I write a slot method in main, and I want to write this slot method outside of main, but I can't seem to find the proper syntax

    int main(int argc, char *argv[])
    {
    }
    void slotToDo(){
    
    }
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      It's just a regular function. There's no special syntax to it.
      If you want to use it inside main it has to be declared above it, like with any other function.

      How are you using it and what error do you get exactly?

      C 1 Reply Last reply
      2
      • Chris KawaC Chris Kawa

        It's just a regular function. There's no special syntax to it.
        If you want to use it inside main it has to be declared above it, like with any other function.

        How are you using it and what error do you get exactly?

        C Offline
        C Offline
        canid
        wrote on last edited by
        #3

        @Chris-Kawa
        I mean it can't be bound with the connect method like a class, how can the connect syntax be written

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Just like for a class member. For example to connect it to a button click:

          QObject::connect(button, &QPushButton::clicked, &slotToDo);
          
          C 1 Reply Last reply
          3
          • Chris KawaC Chris Kawa

            Just like for a class member. For example to connect it to a button click:

            QObject::connect(button, &QPushButton::clicked, &slotToDo);
            
            C Offline
            C Offline
            canid
            wrote on last edited by canid
            #5

            @Chris-Kawa
            Can I define a signal above main and emit it?

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              No, signals are different. They are QObject derived class members and are generated with moc (the meta-object compiler). A signal is kinda what its name implies - it signals a change in some object and making a connection to it subscribes you to notifications about changes in that object. If there's no object there's nothing to signal a change in.

              It's kinda like subscribing to notifications from some website - if there's no website who would you get notifications from?

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved