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

Discuss how to use the Diamond Editor
Post Reply
seasoned_geek
Posts: 253
Joined: Thu Jun 11 2020 12:18 pm

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

Post 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.
ansel
Posts: 152
Joined: Fri Apr 10 2015 8:23 am

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

Post 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: https://www.copperspice.com/docs/cs_overview/m_macros_metaobj.html
Ansel Sermersheim
CopperSpice Cofounder
seasoned_geek
Posts: 253
Joined: Thu Jun 11 2020 12:18 pm

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

Post by seasoned_geek »

Is this also true of signals?
barbara
Posts: 446
Joined: Sat Apr 04 2015 2:32 am
Contact:

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

Post 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.

Barbara
Post Reply