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

Please use this forum for open discussions about Bouml.
Merci d'utiliser ce forum pour des discussions ouvertes à propos de Bouml.

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

Postby coredmp » Mon 16 Oct 2017 11:32

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
coredmp
 
Posts: 8
Joined: Mon 16 Oct 2017 07:57

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

Postby Bruno Pagès » Mon 16 Oct 2017 16:28

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 136 times

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


With these two extra class member definitions :

extra.png
extra.png (19.75 KiB) Viewed 136 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
ImageAuthor of Bouml
Bruno Pagès
 
Posts: 472
Joined: Mon 20 Feb 2012 08:23
Location: France

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

Postby coredmp » Mon 16 Oct 2017 18:42

Yeah ... it works, realy great :)

Thanks a lot for the solution and Bouml :)

Fabrice
coredmp
 
Posts: 8
Joined: Mon 16 Oct 2017 07:57


Return to Open discussions / Discussions ouvertes

Who is online

Users browsing this forum: No registered users and 1 guest

cron