Beginner

|
|
Source code |
1 2 3 4 5 |
... a.connect( &a, SIGNAL( lastWindowClosed () ), &a, SLOT( quit() ) ); a.exec (); ... } |
Quoted
Has someone a little hint for me? Or even a solution?
Beginner
Quoted
Originally posted by Flubb
The plugin has to be as independent as possible from the main program.
Has someone an idea how I could handle that?
Beginner
Beginner
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
// Abstract base class (ABC) that defines an login window interface
// this is what you use in your application
class LoginWindowInterface
{
public:
virtual bool authenticate() = 0;
virtual QString login() const = 0;
virtual QString password() const = 0;
};
// this class implements that interface, but it's provided by the plugin
// you don't need any headers in your application to use it
class LoginWindowImpl : public QDialog, public LoginWindowInterface
{
public:
LoginWindowImpl( QWidget *parent ) : QDialog( parent ) { _ui.setupUi( this ); }
bool authenticate() { return (exec() == QDialog::Accepted); }
QString login() const { return _ui.login->text(); }
QString password() const { return _ui.password->text(); }
};
// abstract login window factory --- create login windows
// this is what your plugin returns when you invoke QPluginLoader::instance()
class LoginWindowFactory : public QObject
{
public:
LoginWindowFactory( QObject *parent ) : QObject( parent ){}
virtual LoginWindowInterface * create( QWidget *parent ) = 0;
};
// concrete factory provided by the plugin
class LoginWindowFactoryImpl : public LoginWindowFactory
{
public:
LoginWindowInterface * create( QWidget *parent ) { return new LoginWindowImpl( parent ); }
};
// sample:
QObject *obj = pluginLoader->instance();
if( obj == 0 ) { ... }
LoginWindowFactory *factory = qobject_cast< LoginWindowFactory * >( obj );
if( factory == 0 ) { /* wrong plugin? */ }
LoginWindowInterface *loginWindow = factory->create( this );
if( loginWindow->authenticate() ) {
QString login = loginWindow->login();
QString password = loginWindow->password();
...
}
else {
/* authentication was cancelled by the user */
}
|
Quoted
Originally posted by Flubb
I googled a lot around and finally I found out, that I can't use interfaces, because I'd like to use signals and slots also.
Quoted
Or running procedual code after closing a specific widget (outside of the library).