Results 1 to 18 of 18

Thread: signal not getting communicated to slot

  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default signal not getting communicated to slot

    hi
    i am currently doing a dialog in which i created 2 check-box, Ok and Cancel button. On press of Ok button 3 signals are emitted communicating state of choices on dialog as shoown below(class is named CockGui). Through this signal i want to choose whether to put my pic on canvas on not. My problem is slot to which signal is connected is not getting executed while there is no reporting of error.


    /*in cockgui.cpp*/
    void CockGui:bnOK_clicked()
    {
    hide();
    emit enableCock(cBoxAllow->isChecked());
    emit enableCockAgain(cBoxAgain->isChecked());
    emit needToRefresh();
    done(1);
    }


    These are connected to slots of different class Cock which uses CockGui.



    void Cock::run()
    {
    CockGui *myPluginGui=new CockGui(mQGisApp, QgisGui::ModalDialogFlags);
    //listen for when the layer has been made so we can draw it
    myPluginGui->setBox(mEnable);
    connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
    connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
    connect(myPluginGui,SIGNAL(enableCock(bool)),this, SLOT(setEnabled(bool)));
    connect(myPluginGui, SIGNAL(needToRefresh()), this, SLOT(refreshCanvas()));
    connect(myPluginGui,SIGNAL(enableCockAgain(bool)), this,SLOT(setEnabled(bool)));
    // refreshCanvas();
    myPluginGui->show();
    }


    void Cock::setEnabled(bool theBool)
    {
    mEnable=theBool;
    QgsProject::instance()->writeEntry("Cock","/Enabled", mEnable );
    if(mEnable)
    cout<<"\nEnable is enabled";
    else
    cout<<"\n not enabled";
    }


    Here none of the cout statement are being displayed on terminal. I traced down to it. Slot setEnabled is not being called so whatever was inital state of mEnable remains.
    Code which will render output on canvas is...

    void Cock::renderCock(QPainter *theQPainter)
    {
    if (mEnable)
    {
    QPixmap myQPixmap; //to store the north arrow image in
    QString myFileNameQString= "/home1/qgis/images/cock/cock.png";
    if (myQPixmap.load(myFileNameQString))
    {

    double centerXDouble = myQPixmap.width()/2;
    double centerYDouble = myQPixmap.height()/2;
    theQPainter->save();

    int myHeight = theQPainter->device()->height();
    int myWidth = theQPainter->device()->width();

    #ifdef QGISDEBUG
    std::cout << "Rendering n-arrow at " << mPlacementLabels.at(mPlacementIndex).toLocal8Bit() .data() << std::endl;

    theQPainter->setRenderHint(QPainter::SmoothPixmapTransform);
    theQPainter->drawPixmap(25,25,myQPixmap);
    //unrotate the canvas again
    theQPainter->restore();
    cout<<"\n rendered";
    }
    else
    {
    QFont myQFont("time", 32, QFont::Bold);
    theQPainter->setFont(myQFont);
    theQPainter->setPen(Qt::black);
    theQPainter->drawText(10, 30, QString(tr("Pixmap1 Not Found")));
    }
    }

    else
    cout<<"\nCock Not enabled";

    }

    Everytime i refresh i gets "Cock Not enabled"

    i couldn't where problem lies. Please help me in it

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: signal not getting communicated to slot

    Have you declare Q_OBJECT in header file ?
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signal not getting communicated to slot

    yes i had done that, if you want i can put header file code also

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal not getting communicated to slot

    In the header file did you put the signals after

    signals:

    and the slots after

    private slots:

    or

    public slots:

  5. #5
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signal not getting communicated to slot

    Here is my header file for Cock class

    #ifndef Cock_H
    #define Cock_H

    //QT4 includes
    #include <QObject>
    #include<QPainter>
    //QGIS includes
    #include <qgisapp.h>
    #include "../qgisplugin.h"


    class QToolBar;

    class Cockublic QObject, public QgisPlugin
    {
    Q_OBJECT
    public:
    Cock(QgisApp * theApplication, QgisIface * theInterface);
    //! Destructor
    virtual ~Cock();
    public slots:
    virtual void initGui();
    void run();
    void unload();
    void help();
    void renderCock(QPainter *thePainter);
    void setEnabled(bool);
    void refreshCanvas();
    void projectRead();
    void drawRasterLayer(QString);
    void drawVectorLayer(QString,QString,QString);

    private:

    bool mEnable;
    int mPluginType;
    //! Pointer to our toolbar
    QToolBar *mToolBarPointer;
    //! Pionter to QGIS main application object
    QgisApp *mQGisApp;
    //! Pointer to the QGIS interface object
    QgisIface *mQGisIface;
    //!pointer to the qaction for this plugin
    QAction * mQActionPointer;


    };

    #endif //Cock_H

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal not getting communicated to slot

    Are you sure that you are emitting the signal in the correct manner?

    Can we see that part of the code as well?

  7. #7
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: signal not getting communicated to slot

    also use CODE tags becouse we see only some abracadabra
    Last edited by zlatko; 1st June 2006 at 11:24.
    a life without programming is like an empty bottle

  8. #8
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signal not getting communicated to slot

    This is the code where i am generating signals. It is in pbnOk_clicked() slot.



    #include "cockgui.h"

    //qt includes

    //standard includes

    CockGui::CockGui() : CockGuiBase()
    {
    setupUi(this);
    }

    CockGui::CockGui( QWidget* parent, Qt::WFlags fl )
    : QDialog ( parent, fl )
    {
    setupUi(this);
    }
    CockGui::~CockGui()
    {
    }

    void CockGui:bnOK_clicked()
    {
    //
    // If you have a produced a raster layer using your plugin, you can ask qgis to
    // add it to the view using:
    // emit drawRasterLayer(QString("layername"));
    // or for a vector layer
    // emit drawVectorLayer(QString("pathname"),QString("layer name"),QString("provider name (either ogr or postgres"));
    //
    //close the dialog
    hide();
    emit enableCock(cBoxAllow->isChecked());
    emit enableCockAgain(cBoxAgain->isChecked());
    emit needToRefresh();
    done(1);
    }
    void CockGui:bnCancel_clicked()
    {
    close(1);
    }
    void CockGui::setBox(bool theBool)
    {
    cBoxAllow->setChecked(theBool);
    }


    i couldn't perceive the meaning of CODE tags. Do you want some explanation about what i am trying to achieve.
    What i am trying to do is to design a plugin for QGIS( open source map viewer) aiming to display a cock to show direction of wind. I generated form using designer. After that i added my functionality to it. class CockGui handles interaction of logic to dialog and class Cock implements that logic.
    I have similar code working there but i don't know what mistake i make here . Ijust couldn't make it out.
    mEnable is a boolean flag which tells plugin to whether to display cock or not. mEnable is set by a slot setBox(bool) (code for it already there). setBox(bool) slot is connected to signal generated in accordance with state of checkboxes.

    i think i have tried to explain my motive. Anything more required please instruct me.

  9. #9
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal not getting communicated to slot

    i couldn't perceive the meaning of CODE tags.
    Write

    "["CODE"]"

    Your code. Use the tags without " "

    "["/CODE"]"

    is pbnOk_clicked() slot called eveytime the button is clicked ?

  10. #10
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signal not getting communicated to slot

    yes. I will recheck it but i am confident about it.

  11. #11
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signal not getting communicated to slot

    thanks man, i think u r right but i am not still sure. While creating dialog i fromed a connection between a slot accept and OK button. I am trying to rectify it now.
    any advices are welcome

  12. #12
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal not getting communicated to slot

    Can we see the code where you make the connection ?

  13. The following user says thank you to munna for this useful post:

    quickNitin (2nd June 2006)

  14. #13
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signal not getting communicated to slot

    i am putting in constructor of CockGui code

    connect(pbnOK,SIGNAL(clicked()),this,SLOT(pbnOK_cl icked()));

  15. #14
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signal not getting communicated to slot

    there is a script which generated basic framework for my plugin code and i followed that and added functionality to it . There is no code in my knowledge which would do job of connecting clicked() signal of ok button with function pbnOK_clicked() (ya it is declared as function); In other plugins this is working well. There is no such connection code. Is it possible? or am i missing sth?
    currently in my code i had made pbnOK_clicked() as a public slot and connected it to clicked event in constructor of CockGUI class. I hope it will work

    Qt Code:
    1. CockGui::CockGui() : CockGuiBase()
    2. {
    3. setupUi(this);
    4. connect(pbnOK,SIGNAL(clicked()),this,SLOT(pbnOK_clicked()));
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 1st June 2006 at 13:16. Reason: fixed code tags

  16. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal not getting communicated to slot

    What happens when you add:
    Qt Code:
    1. connect( myPluginGui, SIGNAL( enableCock( bool ) ), qApp, SLOT( aboutQt() ) );
    To copy to clipboard, switch view to plain text mode 
    after:
    Qt Code:
    1. connect( myPluginGui, SIGNAL( enableCock( bool ) ), this, SLOT( setEnabled( bool ) ) );
    To copy to clipboard, switch view to plain text mode 
    ?
    Are there any message on the console? Do you compile your application in debug mode?

  17. #16
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signal not getting communicated to slot

    after adding the code one dialog appeared telling about qt similat to one which gets generated from help menu of QtDesigner.
    I compiled it in debug mode ( -g option ). and there are nothing as such on terminal excepat statements which i added. One more thing setEnabled() is being called twice after that there is no call . I trying to figure out it.

  18. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal not getting communicated to slot

    Quote Originally Posted by quickNitin
    after adding the code one dialog appeared telling about qt similat to one which gets generated from help menu of QtDesigner.
    So that signal should be OK and probably there is some other code that invokes setEnable() or changes mEnabled.

    Grep your code and check how do you access that mEnabled variable --- maybe you do something like: if( mEnabled = false ) ... ?

    Then set a brakepoint inside the setEnabled() and check the stack trace and values of "sender()" and "theBool".

  19. The following user says thank you to jacek for this useful post:

    quickNitin (2nd June 2006)

  20. #18
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: signal not getting communicated to slot

    you are right. I debugged it back. Accidently i didn't removed code which was reverting setEnabled() action.

    regrads
    nitin k dhiman

Similar Threads

  1. Manually send signal to slot
    By donmorr in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2006, 15:03
  2. Replies: 2
    Last Post: 17th May 2006, 21:01
  3. no such signal QListBox::currentChanged()
    By jopie bakker in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 15:17
  4. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52
  5. No such signal...
    By chaimar in forum Qt Programming
    Replies: 12
    Last Post: 24th January 2006, 22:33

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.