Results 1 to 20 of 21

Thread: Qt 4.2 Shortcut Management

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Wow this example is really great. I think I have most of it integrated into my code properly but I am getting an error:

    Qt Code:
    1. qshortcutmanager.cc: In member function 'void QShortcutManager::destroyed(QObject*)':
    2. qshortcutmanager.cc:396: error: 'quintptr' was not declared in this scope
    To copy to clipboard, switch view to plain text mode 

    I have put qcumber.h into my directory, and the four files for the qshortcut stuff, but I don't really see any other files I'm supposed to include.

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    Wow this example is really great. I think I have most of it integrated into my code properly but I am getting an error:

    Qt Code:
    1. qshortcutmanager.cc: In member function 'void QShortcutManager::destroyed(QObject*)':
    2. qshortcutmanager.cc:396: error: 'quintptr' was not declared in this scope
    To copy to clipboard, switch view to plain text mode 
    I have put qcumber.h into my directory, and the four files for the qshortcut stuff, but I don't really see any other files I'm supposed to include.
    This is weird... quintptr is a very convinient typedef defined in qglobal.h
    I have no idea why it wouldn't compile properly on your box but you can always replace any occurence with : (void*)
    Last edited by fullmetalcoder; 28th February 2007 at 17:35. Reason: typo
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    I just tried adding

    #include <QtGlobal>

    to my qshortcutmanager.cpp file, but it didn't seem to work. It looks like quintptr is declared in QtGlobal, but that change gives the same error.

    http://stuff.mit.edu/afs/athena/soft.../qtglobal.html

  4. #4
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    you know what? It may be a problem that I am actually using Qt 4.1 and not Qt 4.2.

    Qt 4.2 will not install on my mac for some reason, it gets two errors right at the end:

    http://www.qtcentre.org/forum/f-inst...os-x-5867.html

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    you know what? It may be a problem that I am actually using Qt 4.1 and not Qt 4.2.
    That's absolutely right and I hadn't spotted it... I'll place some macro'ed typedef to avoid troubles.
    Current Qt projects : QCodeEdit, RotiDeCode

  6. #6
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    does it save and load the shortcut config files automatically, or do i need to write that in somewhere as another action?

    Also, I just had the strangest problem, and I have no idea what really was happening. When I create the configureShortcuts action, if I use the word "config" or "configure" in the text, it won't load the menu into the menuBar.

    Qt Code:
    1. manageShortcutsAct = new QAction(tr("confshortcuts"),this);
    2. sm->connect( manageShortcutsAct , SIGNAL( triggered() ), SLOT ( configure() ) );
    3. sm->registerAction(manageShortcutsAct, "Configure Shortcuts", "CTRL+M");
    To copy to clipboard, switch view to plain text mode 
    that works.
    Qt Code:
    1. manageShortcutsAct = new QAction(tr("Config Shortcuts"),this);
    2. sm->connect( manageShortcutsAct , SIGNAL( triggered() ), SLOT ( configure() ) );
    3. sm->registerAction(manageShortcutsAct, "Configure Shortcuts", "CTRL+M");
    To copy to clipboard, switch view to plain text mode 
    that does not. I guess it's because I'm using the part of the phrase from the registerAction function. does that make sense?

  7. #7
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    does it save and load the shortcut config files automatically, or do i need to write that in somewhere as another action?
    If you modified qshortcutmanager.cpp, called QApplication::setApplicatioName() and ensured that the settings directory ( QDir::homePath + "/." + QApplication::applicationName() ) exists then saving/reloading should be done flawlessly but as the code you got doesn't do all these steps automatically I guess it does not work properly yet...

    Quote Originally Posted by dvmorris View Post
    Also, I just had the strangest problem, and I have no idea what really was happening. When I create the configureShortcuts action, if I use the word "config" or "configure" in the text, it won't load the menu into the menuBar.

    Qt Code:
    1. manageShortcutsAct = new QAction(tr("confshortcuts"),this);
    2. sm->connect( manageShortcutsAct , SIGNAL( triggered() ), SLOT ( configure() ) );
    3. sm->registerAction(manageShortcutsAct, "Configure Shortcuts", "CTRL+M");
    To copy to clipboard, switch view to plain text mode 
    that works.
    Qt Code:
    1. manageShortcutsAct = new QAction(tr("Config Shortcuts"),this);
    2. sm->connect( manageShortcutsAct , SIGNAL( triggered() ), SLOT ( configure() ) );
    3. sm->registerAction(manageShortcutsAct, "Configure Shortcuts", "CTRL+M");
    To copy to clipboard, switch view to plain text mode 
    that does not. I guess it's because I'm using the part of the phrase from the registerAction function. does that make sense?
    You may want to take a look at the doc (only Doxygen style comments in the source ATM) for this... Actually QShortcutManager doesn't interfere with the action names but only modify the assigned shortcuts. the parameters passed to registerAction() are as follow :
    • a QAction to be managed
    • a QString indicating the context of the action (this is used when storing settings and populating the tree widget of the shortcut dialog ( a '/' in the name indicate a category separator i.e nested categories visible in the tree)
    • a QString indicating the default shortcut. When no shortcuts is set in the configuration it is used. Also when conflicts are encountered when setting shortcuts through the dialog, it may be used as a fallback value.
    The action name is set through the QAction constructor or the setText() method. The menu name is set through the QMenu constructor (and possibly a method but I can't remember which one...)

    Do you mean that using the same text as action name and context causes a bug? Well, I guess I have to check this. Anyway you should indeed avoid using the same text in action name and context because the shortcut dialog would get ugly... As explained above context is a category (meant to contain several actions)...

    Hope this helps you.
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #8
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    I tried setting the applicationName to "topmod" in my main function, and I created the directory

    /Users/dave/.topmod/shortcuts/

    with no files in it. I have one shortcut set to register into the shortcutmanager class, and it gives me an error when i debug saying:

    "Unable to access shortcuts..."

    I even tried this line instead of all that Qt::homeDir() stuff...

    return "/Users/dvmorris/.topmod/shortcuts/shortcuts_en_us.xml";

    none of that seemed to work either.

    *sorry. it works fine now. Thanks for your help again...
    Last edited by dvmorris; 1st March 2007 at 00:36.

  9. #9
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    How do I use the numbers as shortcuts? I can't seem to get them to work by themselves without adding a CTRL or ALT key before them.

    For example, I have a QTabWidget with five pages and I setup five modes like this

    Qt Code:
    1. modeBasicsAct = new QAction(QIcon(":/images/mode_basics.png"), tr("&Basics"), this);
    2. sm->registerAction(modeBasicsAct, "Modes", "1");
    3. modeBasicsAct->setStatusTip(tr("Switch to Basics Mode"));
    4. connect(modeBasicsAct, SIGNAL(triggered()), this, SLOT(switchMode(0)));
    To copy to clipboard, switch view to plain text mode 

    and I have a slot function defined like this:

    Qt Code:
    1. void MainWindow::switchMode(int pageId){
    2. modesTabWidget->setCurrentIndex(pageId);
    3. }
    To copy to clipboard, switch view to plain text mode 

    The 1,2,3,4,5 shortcuts I set with registerAction do not switch the TabWidget's currentIndex to 0,1,2,3,or 4, like I write in the slot function.

    Do you have any ideas as to why that won't work? I also noticed that it doesn't seem to work with any other shortcuts like CTRL+L. Maybe this has nothing to do with the numbers problem. anyways, sorry to bother you so much. I really appreciate your help. Your shortcut manager is phenomenal.

  10. #10
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    How do I use the numbers as shortcuts? I can't seem to get them to work by themselves without adding a CTRL or ALT key before them.

    For example, I have a QTabWidget with five pages and I setup five modes like this

    Qt Code:
    1. modeBasicsAct = new QAction(QIcon(":/images/mode_basics.png"), tr("&Basics"), this);
    2. sm->registerAction(modeBasicsAct, "Modes", "1");
    3. modeBasicsAct->setStatusTip(tr("Switch to Basics Mode"));
    4. connect(modeBasicsAct, SIGNAL(triggered()), this, SLOT(switchMode(0)));
    To copy to clipboard, switch view to plain text mode 
    and I have a slot function defined like this:

    Qt Code:
    1. void MainWindow::switchMode(int pageId){
    2. modesTabWidget->setCurrentIndex(pageId);
    3. }
    To copy to clipboard, switch view to plain text mode 
    The 1,2,3,4,5 shortcuts I set with registerAction do not switch the TabWidget's currentIndex to 0,1,2,3,or 4, like I write in the slot function.

    Do you have any ideas as to why that won't work? I also noticed that it doesn't seem to work with any other shortcuts like CTRL+L. Maybe this has nothing to do with the numbers problem. anyways, sorry to bother you so much. I really appreciate your help. Your shortcut manager is phenomenal.
    The shortcut management provided is just a (very ) convinient wrapper over Qt shortcut mechanism but it doesn't modify it... AFAIK shortcuts NEED modifiers to work because other keys are generally forwarded to other widgets and this is especially true if you have, say, any kind of input widget in your current tab...

    Besides your slots registration is wrong : the SLOT() macro is passed a qualified function name ( name + parameters types) and no arguments... That's probably why your code is failing. If you use a special slot for each mode switching and make sure that the child widgets don't accept number keys input it should work...
    Current Qt projects : QCodeEdit, RotiDeCode

  11. #11
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    ok I understand a little better now. I rewrote the slot functions so there is a unique one for each of the five TabWidget Pages. here is one of them:

    Qt Code:
    1. //inside MainWindow class in .h file
    2. private slots:
    3. void switchBasicsMode();
    4.  
    5. //in cpp file
    6. void MainWindow::switchBasicsMode(){
    7. modesTabWidget->setCurrentIndex(0);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. modeBasicsAct = new QAction(QIcon(":/images/mode_basics.png"), tr("&Basics"), this);
    2. sm->registerAction(modeBasicsAct, "Modes", "CTRL+9");
    3. modeBasicsAct->setStatusTip(tr("Switch to Basics Mode"));
    4. connect(modeBasicsAct, SIGNAL(triggered()), this, SLOT(switchBasicsMode()));
    To copy to clipboard, switch view to plain text mode 

    but that doesn't seem to work either. the signals slots demo here: http://doc.trolltech.com/4.2/signalsandslots.html is not very helpful either.

    The shortcut doesn't seem to do anything. But all the shortcuts for actions that are attached to menuBar items work fine (except single numbers and CTRL+Q). Do I just need to create a dummy menuBar for the five modes so that the shortcuts will do something?

  12. #12
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    The shortcut doesn't seem to do anything. But all the shortcuts for actions that are attached to menuBar items work fine (except single numbers and CTRL+Q). Do I just need to create a dummy menuBar for the five modes so that the shortcuts will do something?
    I forgot to point this out as well... Qt, as far as I tested, forward shortcuts to VISIBLE actions only... If you don't attach your actions to menubars, toolbars, buttons or anything that can manage them, then the shortcut will never trigger the actions (except maybe if you play with the shortcut context but even that may fail...)
    Current Qt projects : QCodeEdit, RotiDeCode

  13. #13
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    I'm attempting to compile this program on Windows, and it gives the following error:

    debug\moc_qshortcutdialog.cpp:40: error: definition of static data member 'QShortcutDialog::staticMetaObject' of dllimport'd class.
    debug\moc_qshortcutdialog.cpp:40: warning: 'QShortcutDialog::staticMetaObject' defined locally after being referenced with dllimport linkage
    mingw32-make[1]: *** [debug\moc_qshortcutdialog.o] Error 1
    mingw32-make[1]: Leaving directory `C:/Documents and Settings/dave/Desktop/thesis/topmod/trunk'
    mingw32-make: *** [debug] Error 2
    I found a post that you answered about a similar problem here:

    http://www.qtcentre.org/forum/f-qt-s...rary-3286.html

    but I'm not sure how to implement your fix in this case. Do you have any suggestions? Thanks for the help,
    dave
    Last edited by jacek; 5th March 2007 at 23:47. Reason: changed [code] to [quote]

  14. #14
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    I just tried adding

    #include <QtGlobal>

    to my qshortcutmanager.cpp file, but it didn't seem to work. It looks like quintptr is declared in QtGlobal, but that change gives the same error.

    http://stuff.mit.edu/afs/athena/soft.../qtglobal.html
    it is documented here : http://stuff.mit.edu/afs/athena/soft...intptr-typedef

    and should be defined in any context provided that you have ANY Qt header included in the source. This is the case in qshortcutmanager.cpp so my only suggestion is to try #include "qglogal.h" and if it still doesn't work replace the occurence or add the typedef by hand in the source file :
    Qt Code:
    1. typedef void* quintptr;
    To copy to clipboard, switch view to plain text mode 
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Replies: 1
    Last Post: 9th February 2007, 09:41
  2. shortcut with more than one key
    By ChasW in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2007, 06:38
  3. Trying to set shortcut
    By mikro in forum Newbie
    Replies: 2
    Last Post: 30th November 2006, 09:55
  4. Memory management in QT
    By Gayathri in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2006, 07:21
  5. Multi frame management ... is it possible ?
    By yellowmat in forum Newbie
    Replies: 8
    Last Post: 25th January 2006, 10:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.