Page 1 of 1

Maybe I'm just tired or can't read?

Posted: Thu Aug 27 2020 12:38 am
by seasoned_geek
I thought a slot had to be wrapped in CS_SLOT_1() CS_SLOT_2() in the header file in order for it to be used via connect() as a slot.

Spent most of today trying to track down a focus problem when closing the advanced find window. The text edit tab doesn't actually get keyboard focus. The Close pushbutton always seems to get focus back once again. Finally I went to declare a simple slot just for the button, one that wasn't re-used to clean-up an existing and now unwanted split (so I could cheat with a timer) . . . and this rattled the noodle.

I pulled up the master code that I have from when I pulled/forked/whatever-git-calls-it-when-one-is-working-on-changes-before-a-pull-request

split_window.cpp line 104

Code: Select all

connect(m_splitClose_PB,  &QPushButton::clicked, this, &MainWindow::split_CloseButton);
mainwindow.h lines 475-480

Code: Select all

      // split
      void set_splitCombo();
      void split_Horizontal();
      void split_Vertical();
      void split_NameChanged(int data);
      void split_CloseButton();
I'm not saying this should be fixed in Diamond. I'm replacing it right now and not back-linked or whatever GitHub calls it. I'm redoing that little bit of code now.

I'm bringing this up because it is my understanding this should have died at compile time. Perhaps I'm just thick as a brick and making a baseless statement, but that was my understanding of the slot macros.

I'm probably just confused. It has been a long day.

Re: Maybe I'm just tired or can't read?

Posted: Thu Aug 27 2020 5:16 pm
by ansel
The code in Diamond is correct. You may not be aware that there are multiple overloads of the connect() method.

We have added a note to our CopperSpice Overview documentation to indicate slots only need to be registered if they are used with the string overload of connect(). Since Diamond uses method pointers in every connect() call, the registration is unnecessary.

See the text at the bottom of:

Re: Maybe I'm just tired or can't read?

Posted: Thu Aug 27 2020 9:08 pm
by seasoned_geek
Is this also true of signals?

Re: Maybe I'm just tired or can't read?

Posted: Sat Aug 29 2020 7:56 pm
by barbara
Signals must always be registered, so yes the CS macro registration syntax must be used. If you are passing the Slot as a string or using the SLOT() macro then you also need to register it.

You do not need to register a Slot when a method pointer is used in the call to connect(). This is the preferred way since we can then avoid a string lookup at runtime.