Page 1 of 1

how to Add QT "slots" in class header ( C++ )

PostPosted: Mon 16 Oct 2017 12:32
by coredmp
Hello,

In Qt 5.9, they are using "connect" function in order to connect event and method.

For that thez add a "slots" name in header file. For example, if you want to use a QTimer, you declare the method like this in your class :

...
private slots:
void timerFired();
....


And you connect your timer like this (if this is a method of your class ) :

...
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timerFired()));
timer->start(1000);
...

I didn't manage to make this "private slots:" in Bouml ( i manage to make it in C++ generated mode, but it did not survice to a reverse C++ ) ...

Is there a solution ?

Thanks

Fabrice

Re: how to Add QT "slots" in class header ( C++ )

PostPosted: Mon 16 Oct 2017 17:28
by Bruno Pagès
Hello,

Bouml is implemented on QT(4), so I am a little bit concerned by Qt ;)

You can both generate slots and reverse/roundtrip code containing slots, for instance having these two files in a directory :

Code: Select all
// MyDialog.h

#include <qdialog.h>

class MyDialog : public QDialog {
  Q_OBJECT
   
  public:
    MyDialog();
    virtual ~MyDialog();
 
  protected slots:
    virtual void accept();
};


Code: Select all
// MyDialog.cpp
#include "MyDialog.h"

MyDialog::MyDialog() {
  // ...
}

MyDialog::~MyDialog() {
  // ...
}

void MyDialog::accept() {
  // ...
}


Reversing the directory containing them I obtain :

trace.png
trace.png (19.31 KiB) Viewed 4406 times

browser.png
browser.png (24.62 KiB) Viewed 4406 times


With these two extra class member definitions :

extra.png
extra.png (19.75 KiB) Viewed 4406 times


typedef1 is typedef QDialog typedef1; to manage the unknown class QDialog

If I generate the code this produces

Code: Select all
class MyDialog : public typedef1 {
  Q_OBJECT
  public:
    MyDialog();

    virtual ~MyDialog();

  protected slots:
  protected:
    virtual void accept();

};


so there is an unexpected protected: but there are several solution to not have it, for instance to put the extra member and operations after protected members

Re: how to Add QT "slots" in class header ( C++ )

PostPosted: Mon 16 Oct 2017 19:42
by coredmp
Yeah ... it works, realy great :)

Thanks a lot for the solution and Bouml :)

Fabrice