Results 1 to 5 of 5

Thread: Bouncing button problems

  1. #1
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Bouncing button problems

    I'm sure this is some kind of rank newbie mistake, but I cannot seem to discover what I am doing wrong.

    I've got several buttons, each with their "clicked" signal hooked to a slot to do various functions. However, it seems that when the app is running, when the user clicks on one of the buttons, two clicked signals are received by the app.

    For instance, one of the buttons uses QDesktopServices:penUrl to invoke the system's web browser and send it to a certain web page. When the button is clicked once, Firefox appears with two tabs, both set to the same web page.

    The same thing happens when the keyboard shortcut for the button is typed.

    Any ideas of what I am doing wrong?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Bouncing button problems

    Can you post the code where you connect the button signals and where you create the actions. Or at least describe the problem a bit?

    The most common reason is that you connected somehow the clicked signal twice to the same slot.
    So, when it is emitted, the slot gets called twice.

    Regards

  3. #3
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Bouncing button problems

    Qt 4.2.3, compiled statically
    MS Visual Studio 2005

    In myMainWindow.h
    Qt Code:
    1. class myMainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. myMainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
    7. ~myMainWindow();
    8. ...
    9.  
    10. private slots:
    11. void on_aboutUs_clicked(bool checked);
    12. ...
    13. };
    To copy to clipboard, switch view to plain text mode 


    In myMainWindow.cpp
    Qt Code:
    1. myMainWindow::myMainWindow(QWidget *parent, Qt::WFlags flags)
    2. : QMainWindow(parent, flags)
    3. {
    4. ui.setupUi(this);
    5. connect(ui.aboutUs, SIGNAL(clicked(bool)), this, SLOT(on_aboutUs_clicked(bool)));
    6. ...
    7. }
    8.  
    9. myMainWindow::on_aboutUs_clicked(bool checked)
    10. {
    11. QDesktopServices::openUrl(QUrl(tr("http://www.whatever.com/about.html")));
    12. }
    To copy to clipboard, switch view to plain text mode 

    In ui_myMainWindow.h
    Qt Code:
    1. class Ui_myMainWindowClass
    2. {
    3. public:
    4. QPushButton *aboutUs;
    5. ...
    6. aboutUs= new QPushButton(page_2);
    7. aboutUs->setObjectName(QString::fromUtf8("aboutUs"));
    8. aboutUs->setGeometry(QRect(11, 0, 195, 27));
    9. aboutZeiss->setIcon(QIcon(QString::fromUtf8(":/myMainWindow/Resources/AboutUs.png")));
    To copy to clipboard, switch view to plain text mode 
    As you can see there is not much to it. When the button is clicked, two instances of the URL are opened. I've set breakpoints in the slot and yes indeed it gets called twice. This happens with all ten buttons in the app.

    As a work-around, I'm experimenting with using the "released" signal instead of the "clicked" signal.
    Last edited by WinchellChung; 25th June 2007 at 22:12.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Bouncing button problems

    "on_aboutUs_clicked" follows the naming convention of automatic connections. Therefore the connection is established twice; 1) automatically 2) by hand.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    WinchellChung (25th June 2007)

  6. #5
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Bouncing button problems

    Automatic connections! That explains it.
    I had not gotten that far in the book so I had never heard of them. I used that naming convention because the book used it.

    Thanks!

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.