how to use KGlobalAccel - KDE

This is a discussion on how to use KGlobalAccel - KDE ; here is my code but it seems didn't work ====================main.cpp============== #include "KT.h" #include #include #include int main(int argc, char **argv) { KAboutData about("xxx", "xxx" ,"0.1", "xxx", KAboutData::License_GPL, "timgreen" , "", "http://"); KCmdLineArgs::init(argc, argv, &about); KUniqueApplication::addCmdLineOptions(); if (!KUniqueApplication::start()) { //already start ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: how to use KGlobalAccel

  1. how to use KGlobalAccel

    here is my code
    but it seems didn't work


    ====================main.cpp==============
    #include "KT.h"
    #include
    #include
    #include

    int main(int argc, char **argv) {
    KAboutData about("xxx", "xxx" ,"0.1",
    "xxx", KAboutData::License_GPL,
    "timgreen" , "",
    "http://");
    KCmdLineArgs::init(argc, argv, &about);
    KUniqueApplication::addCmdLineOptions();

    if (!KUniqueApplication::start()) {
    //already start
    return 0;
    }

    KUniqueApplication a;
    KT *w = new KT();
    w->setGeometry(100,100,600,300);

    a.setMainWidget(w);
    w->show();
    return a.exec();
    }
    ====================KT.h=================
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    //Added by qt3to4:
    //#include
    //#include

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    //#include
    #include
    #include
    #include

    //#include


    class KT : public KMainWindow {
    Q_OBJECT
    public:
    KT();
    ~KT();
    public slots:
    void slotT();
    void slotK();
    private:
    QLabel *label;
    QPushButton *btn, *btn2;
    KGlobalAccel *kga;
    };
    ====================KT.cpp===================
    #include "KT.moc"

    KT::KT() {

    kga = new KGlobalAccel(this);

    kga->insert("TTT", "TTT", "...", ALT+Key_A, KShortcut(), this,
    SLOT(slotT));
    kga->updateConnections();

    label = new QLabel("", this); label->setGeometry(45,30,50,25);
    label->show();

    btn = new QPushButton("Work", this);
    btn->setGeometry(105,30,50,25);
    btn->show();
    connect(btn, SIGNAL(clicked()), this, SLOT(slotT()));

    btn2 = new QPushButton("Key", this);
    btn2->setGeometry(165,30,50,25);
    btn2->show();
    connect(btn2, SIGNAL(clicked()), this, SLOT(slotK()));
    }

    KT::~KT() {
    }

    void KT::slotT() {
    static bool flag = false;
    flag = !flag;
    label->setText("work! " + QString::number(flag));
    }
    void KT::slotK() {
    KKeyDialog::configure(kga, this);
    }


  2. Re: how to use KGlobalAccel

    timgreen wrote:

    > here is my code
    > but it seems didn't work
    >
    >
    > ====================main.cpp==============
    > #include "KT.h"
    > #include
    > #include
    > #include
    >
    > int main(int argc, char **argv) {
    > KAboutData about("xxx", "xxx" ,"0.1",
    > "xxx", KAboutData::License_GPL,
    > "timgreen" , "",
    > "http://");
    > KCmdLineArgs::init(argc, argv, &about);
    > KUniqueApplication::addCmdLineOptions();
    >
    > if (!KUniqueApplication::start()) {
    > //already start
    > return 0;
    > }
    >
    > KUniqueApplication a;
    > KT *w = new KT();
    > w->setGeometry(100,100,600,300);
    >
    > a.setMainWidget(w);
    > w->show();
    > return a.exec();
    > }
    > ====================KT.h=================
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    >
    > //Added by qt3to4:
    > //#include
    > //#include
    >
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > //#include
    > #include
    > #include
    > #include
    >
    > //#include
    >
    >
    > class KT : public KMainWindow {
    > Q_OBJECT
    > public:
    > KT();
    > ~KT();
    > public slots:
    > void slotT();
    > void slotK();
    > private:
    > QLabel *label;
    > QPushButton *btn, *btn2;
    > KGlobalAccel *kga;
    > };
    > ====================KT.cpp===================
    > #include "KT.moc"
    >
    > KT::KT() {
    >
    > kga = new KGlobalAccel(this);
    >
    > kga->insert("TTT", "TTT", "...", ALT+Key_A, KShortcut(), this,
    > SLOT(slotT));
    > kga->updateConnections();
    >
    > label = new QLabel("", this); label->setGeometry(45,30,50,25);
    > label->show();
    >
    > btn = new QPushButton("Work", this);
    > btn->setGeometry(105,30,50,25);
    > btn->show();
    > connect(btn, SIGNAL(clicked()), this, SLOT(slotT()));
    >
    > btn2 = new QPushButton("Key", this);
    > btn2->setGeometry(165,30,50,25);
    > btn2->show();
    > connect(btn2, SIGNAL(clicked()), this, SLOT(slotK()));
    > }
    >
    > KT::~KT() {
    > }
    >
    > void KT::slotT() {
    > static bool flag = false;
    > flag = !flag;
    > label->setText("work! " + QString::number(flag));
    > }
    > void KT::slotK() {
    > KKeyDialog::configure(kga, this);
    > }


    Is this for KDE 3 or KDE 4? If it's KDE 4, I would recommend using KAction
    and it's setGlobalShortcut method instead. KGlobalAccel in KDE 4 doesn't
    have an insert method either.

    Hope this helps.
    --
    Matt

  3. Re: how to use KGlobalAccel

    Matt Rogers 写道:

    > timgreen wrote:
    >
    > > here is my code
    > > but it seems didn't work
    > >
    > >
    > > ====================main.cpp==============
    > > #include "KT.h"
    > > #include
    > > #include
    > > #include
    > >
    > > int main(int argc, char **argv) {
    > > KAboutData about("xxx", "xxx" ,"0.1",
    > > "xxx", KAboutData::License_GPL,
    > > "timgreen" , "",
    > > "http://");
    > > KCmdLineArgs::init(argc, argv, &about);
    > > KUniqueApplication::addCmdLineOptions();
    > >
    > > if (!KUniqueApplication::start()) {
    > > //already start
    > > return 0;
    > > }
    > >
    > > KUniqueApplication a;
    > > KT *w = new KT();
    > > w->setGeometry(100,100,600,300);
    > >
    > > a.setMainWidget(w);
    > > w->show();
    > > return a.exec();
    > > }
    > > ====================KT.h=================
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > >
    > > //Added by qt3to4:
    > > //#include
    > > //#include
    > >
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > //#include
    > > #include
    > > #include
    > > #include
    > >
    > > //#include
    > >
    > >
    > > class KT : public KMainWindow {
    > > Q_OBJECT
    > > public:
    > > KT();
    > > ~KT();
    > > public slots:
    > > void slotT();
    > > void slotK();
    > > private:
    > > QLabel *label;
    > > QPushButton *btn, *btn2;
    > > KGlobalAccel *kga;
    > > };
    > > ====================KT.cpp===================
    > > #include "KT.moc"
    > >
    > > KT::KT() {
    > >
    > > kga = new KGlobalAccel(this);
    > >
    > > kga->insert("TTT", "TTT", "...", ALT+Key_A, KShortcut(), this,
    > > SLOT(slotT));
    > > kga->updateConnections();
    > >
    > > label = new QLabel("", this); label->setGeometry(45,30,50,25);
    > > label->show();
    > >
    > > btn = new QPushButton("Work", this);
    > > btn->setGeometry(105,30,50,25);
    > > btn->show();
    > > connect(btn, SIGNAL(clicked()), this, SLOT(slotT()));
    > >
    > > btn2 = new QPushButton("Key", this);
    > > btn2->setGeometry(165,30,50,25);
    > > btn2->show();
    > > connect(btn2, SIGNAL(clicked()), this, SLOT(slotK()));
    > > }
    > >
    > > KT::~KT() {
    > > }
    > >
    > > void KT::slotT() {
    > > static bool flag = false;
    > > flag = !flag;
    > > label->setText("work! " + QString::number(flag));
    > > }
    > > void KT::slotK() {
    > > KKeyDialog::configure(kga, this);
    > > }

    >
    > Is this for KDE 3 or KDE 4? If it's KDE 4, I would recommend using KAction
    > and it's setGlobalShortcut method instead. KGlobalAccel in KDE 4 doesn't
    > have an insert method either.
    >
    > Hope this helps.
    > --
    > Matt

    thx!
    shortcut work!

    but in kde3 I did not find setGlobalShortcut for KAction
    if I want my problem works in kde3 what can I use instead.


  4. Re: how to use KGlobalAccel


    Matt Rogers 写道:

    > timgreen wrote:
    >
    > > here is my code
    > > but it seems didn't work
    > >
    > >
    > > ====================main.cpp==============
    > > #include "KT.h"
    > > #include
    > > #include
    > > #include
    > >
    > > int main(int argc, char **argv) {
    > > KAboutData about("xxx", "xxx" ,"0.1",
    > > "xxx", KAboutData::License_GPL,
    > > "timgreen" , "",
    > > "http://");
    > > KCmdLineArgs::init(argc, argv, &about);
    > > KUniqueApplication::addCmdLineOptions();
    > >
    > > if (!KUniqueApplication::start()) {
    > > //already start
    > > return 0;
    > > }
    > >
    > > KUniqueApplication a;
    > > KT *w = new KT();
    > > w->setGeometry(100,100,600,300);
    > >
    > > a.setMainWidget(w);
    > > w->show();
    > > return a.exec();
    > > }
    > > ====================KT.h=================
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > >
    > > //Added by qt3to4:
    > > //#include
    > > //#include
    > >
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > //#include
    > > #include
    > > #include
    > > #include
    > >
    > > //#include
    > >
    > >
    > > class KT : public KMainWindow {
    > > Q_OBJECT
    > > public:
    > > KT();
    > > ~KT();
    > > public slots:
    > > void slotT();
    > > void slotK();
    > > private:
    > > QLabel *label;
    > > QPushButton *btn, *btn2;
    > > KGlobalAccel *kga;
    > > };
    > > ====================KT.cpp===================
    > > #include "KT.moc"
    > >
    > > KT::KT() {
    > >
    > > kga = new KGlobalAccel(this);
    > >
    > > kga->insert("TTT", "TTT", "...", ALT+Key_A, KShortcut(), this,
    > > SLOT(slotT));
    > > kga->updateConnections();
    > >
    > > label = new QLabel("", this); label->setGeometry(45,30,50,25);
    > > label->show();
    > >
    > > btn = new QPushButton("Work", this);
    > > btn->setGeometry(105,30,50,25);
    > > btn->show();
    > > connect(btn, SIGNAL(clicked()), this, SLOT(slotT()));
    > >
    > > btn2 = new QPushButton("Key", this);
    > > btn2->setGeometry(165,30,50,25);
    > > btn2->show();
    > > connect(btn2, SIGNAL(clicked()), this, SLOT(slotK()));
    > > }
    > >
    > > KT::~KT() {
    > > }
    > >
    > > void KT::slotT() {
    > > static bool flag = false;
    > > flag = !flag;
    > > label->setText("work! " + QString::number(flag));
    > > }
    > > void KT::slotK() {
    > > KKeyDialog::configure(kga, this);
    > > }

    >
    > Is this for KDE 3 or KDE 4? If it's KDE 4, I would recommend using KAction
    > and it's setGlobalShortcut method instead. KGlobalAccel in KDE 4 doesn't
    > have an insert method either.
    >
    > Hope this helps.
    > --
    > Matt


    I just find out my stupid mistake.
    I forgot () in kga.insert ---- SLOT(slotT()).
    and now KGlobalAccel works fine.

    and thank you.


+ Reply to Thread