Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Why my defined QAction has no response?

[Solved]Why my defined QAction has no response?

Scheduled Pinned Locked Moved General and Desktop
16 Posts 3 Posters 5.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mybiandou
    wrote on last edited by
    #1

    Hello, everyone.

    I am a beginner of Qt programming.

    I just make a simple exercise following example "widgets-imageviewer":http://doc.qt.digia.com/latest/widgets-imageviewer.html

    In my program , I made a QAction "rgbFilterAct" under QMenu "processingMenu" , and connected it with function filterRGB(void) to display a RGB range choosing dialogue.

    But it has no response after I click the menu item rgbFilterAct.

    Can anyone kindly tell me why.

    The following is my code.

    @
    // main.cpp//
    #include <QApplication>
    #include "mainwindow.h"
    #include "rgbdlg.h"
    int main(int argc,char **argv)
    {

    QApplication app(argc, argv);
    MainWindow *mwin =new MainWindow();
    mwin->show();
    return app.exec();
    }

    @

    @
    //MainWindow.h
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QtGui>
    #include "rgbdlg.h"

    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MainWindow(QWidget *parent = 0);
    QAction *openAct;
    QAction *quitAct;

    QAction *rgbFilterAct;
    
    QMenuBar *menubar;
    
    QMenu *fileMenu;
    QMenu *processingMenu;
    
    QLabel *imgLabel;
    QScrollArea *scrollArea;
    QImage imgsrc,imgdst;
    
    double scaleFactor;
    
    RGBDlg *rgbDlg;
    

    signals:

    public slots:
    void open();
    void save();
    void quit();
    void filterRGB();

    };

    #endif // MAINWINDOW_H

    @

    @
    //MainWindow.cpp
    #include "mainwindow.h"
    #include "rgbdlg.h"
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    {
    this->setWindowTitle(tr("Filter image By Color "));

    openAct = new QAction(tr("&Open..."),this);
    quitAct = new QAction(tr("&Quit"),this);
    
    rgbFilterAct = new QAction(tr("&Filter RGB"),this);
    
    this->connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
    this->connect(quitAct, SIGNAL(triggered()), this, SLOT(quit()));
    this->connect(rgbFilterAct,SIGNAL(triggereed()),this,SLOT(filterRGB()));
    
    
    fileMenu = new QMenu(tr("&File"),this);
    fileMenu->addAction(openAct);
    fileMenu->addAction(quitAct);
    
    processingMenu= new QMenu(tr("&Processing"),this);
    processingMenu->addAction(rgbFilterAct);
    
    menubar=new QMenuBar;
    
    menubar->addMenu(fileMenu);
    menubar->addMenu(processingMenu);
    
    imgLabel = new QLabel;
    imgLabel->setBackgroundRole(QPalette::Base);
    imgLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    imgLabel->setScaledContents(true);
    
    scrollArea = new QScrollArea;
    scrollArea->setBackgroundRole(QPalette::Dark);
    scrollArea->setWidget(imgLabel);
    
    this->setMenuBar(menubar);
    this->setCentralWidget(scrollArea);
    
    scaleFactor=1.0;
    rgbDlg=NULL;
    
    this->resize(800,600);
    this->show();
    

    }

    void MainWindow::open(void)
    {
    QString fileName = QFileDialog::getOpenFileName(this,
    tr("Open File"), QDir::currentPath());
    if (!fileName.isEmpty()) {
    QImage imgsrc(fileName);
    if (imgsrc.isNull()) {
    QMessageBox::information(this, tr("FilterImageByColor"),
    tr("Cannot load %1.").arg(fileName));
    return;
    }
    imgdst=imgsrc;
    imgLabel->setPixmap(QPixmap::fromImage(imgdst));
    scaleFactor=1.0;
    imgLabel->resize(imgLabel->pixmap()->size());
    return ;
    }
    return ;
    }

    void MainWindow::save(void)
    {
    return ;
    }

    void MainWindow::quit(void)
    {
    if(QMessageBox::Yes==QMessageBox::question(this,tr("FileterImageByColor"),
    tr("Do you want to really quit program?"),
    QMessageBox::Yes | QMessageBox::No,QMessageBox::No))
    {
    QApplication::quit();
    }
    return;
    }

    void MainWindow::filterRGB(void)
    {
    if(!rgbDlg) {
    rgbDlg = new RGBDlg(this);
    }
    rgbDlg->exec();
    return ;
    }
    @

    @
    //rgbdlg.h
    #ifndef RGBDLG_H
    #define RGBDLG_H

    #include <QDialog>
    #include <QtGUI>
    class RGBDlg : public QDialog
    {
    Q_OBJECT
    public:
    RGBDlg(QWidget *parent = 0);

    signals:

    public slots:

    };

    #endif // RGBDLG_H

    @

    @
    //rgbdlg.cpp
    #include "rgbdlg.h"

    RGBDlg::RGBDlg(QWidget *parent) :
    QDialog(parent)
    {
    }

    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gayu
      wrote on last edited by
      #2

      Think so u r using Qt4. Whether the code runs fine without showing any errors?
      I checked the code whether it is running or not.
      But,the code works fine for me.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        Hi ,

        Welcome to DEVNET,

        If you check line 16 of mainwindow.cpp I think there is a mistake with

        @this->connect(rgbFilterAct,SIGNAL(triggereed()),this,SLOT(filterRGB()));@

        triggered() should be used ,spelling mistake/ you dont have any SIGNAL : triggereed() declaration for RGBDlg.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          [quote author="gayu" date="1353394688"]Think so u r using Qt4. Whether the code runs fine without showing any errors?
          I checked the code whether it is running or not.
          But,the code works fine for me.[/quote]

          The Project compiles n Runs successfully but for him the QAction is not working . Did you check with the requirements as I see if you click on Processing->Filter RGB it does not open RGBDlg, as there is a spelling mistake for the SIGNAL that he/she is trying to connect.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gayu
            wrote on last edited by
            #5

            Whether the QAction is not working for him

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mybiandou
              wrote on last edited by
              #6

              Thank you, Sam

              You are quire right.

              I am sorry for my silly problem. It confused me for a week.

              I really wish the meta object compiler can help much.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sam
                wrote on last edited by
                #7

                You are welcome,

                bq. I am sorry for my silly problem.

                No need, we all are here to learn :)

                Kindly Edit your first post and prepend [Solved] to the title.

                Happy Coding !!

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gayu
                  wrote on last edited by
                  #8

                  In my project i also used the same QAction, but when compiling it show some errors.
                  Thats y i asked u about the QAction. Will u please tell me about that

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Sam
                    wrote on last edited by
                    #9

                    [quote author="gayu" date="1353399435"]In my project i also used the same QAction, but when compiling it show some errors.
                    Thats y i asked u about the QAction. Will u please tell me about that[/quote]

                    What errors are you getting ?

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gayu
                      wrote on last edited by
                      #10

                      ERROR
                      no matching function for call to ‘QAction::QAction(QString, QPixmap, QString, unsigned int, mainForm* const, const char [8])’

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Sam
                        wrote on last edited by
                        #11

                        And how are you connecting the signals and slots ? Kindly share your code .

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          gayu
                          wrote on last edited by
                          #12

                          Ya sure
                          The following is the main.cpp file

                          @
                          #include <qapplication.h>
                          #include "mainform.h"

                          int main( int argc, char ** argv )
                          {
                          QApplication a( argc, argv );
                          mainForm w;
                          w.show();
                          a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
                          return a.exec();
                          }
                          @
                          The following code is somewhere in the mainform.cpp file

                          @
                          void mainForm::setupLanguageActions()
                          {

                          Q3ToolBar *tb = new Q3ToolBar( this );
                          tb->setLabel( "Language Actions" );
                          Q3PopupMenu *menu = new Q3PopupMenu( this );
                          menuBar()->insertItem( tr( "&Language" ), menu );
                          
                          Q3Action *a;
                          a = new Q3Action( tr( "Tamil" ), tr( "&Tamil" ), Qt::CTRL + Qt::Key_Z, this, "langtamil" );
                          connect( a, SIGNAL( activated() ), this, SLOT( ChangeLangTamil() ) );
                          a->addTo( tb );
                          a->addTo( menu );
                          
                          a = new Q3Action( tr( "Hindi" ), tr( "&Hindi" ), Qt::CTRL + Qt::Key_Y, this, "langhindi" );
                          connect( a, SIGNAL( activated() ), this, SLOT( ChangeLangHindi() ) );
                          a->addTo( tb );
                          a->addTo( menu );
                          

                          }
                          @
                          And also for more actions..

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            Sam
                            wrote on last edited by
                            #13

                            Are you including the proper header files , Try including QObject header and build.
                            Also check for the proper signature of Q3Action class .

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              gayu
                              wrote on last edited by
                              #14

                              Might what the question i'm asking is silly, but please tell me
                              Whether Qt4 support QAction

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                Sam
                                wrote on last edited by
                                #15

                                [quote author="gayu" date="1353403125"]Might what the question i'm asking is silly, but please tell me
                                Whether Qt4 support QAction[/quote]

                                Ofcourse Qt4 support QAction ,you can have a look in "Porting to Qt 4":http://qt-project.org/doc/qt-4.8/porting4.html#qaction and "QAction":http://qt-project.org/doc/qt-4.8/qaction.html class.

                                But why are you still working in Qt 3 ?

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  gayu
                                  wrote on last edited by
                                  #16

                                  So when using Q3ToolBar and Q3PopupMenu, their actions must be Q3Actions.
                                  Otherwise the QAction itself is used right.

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved