×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    43

    Red face Receiving signal of static object

    Hello Friends, I declared static object in my project if my user defined class in another class. So can I receive emmited signals of that static object? Here's exact situation. I have MyUtil class in my project. In that I have declared QTimer class. In MyUtil class I have define method to receive timeout event. If time occur by QTimer class it will call my timeout method and that time out method will emit signal called myTimeout().

    I have another class in my project say, LocationData. In Location data class, I have created static MyUtil class object. Now from another class called SubmitData, I am trying to connect static object of MyUtil class of LocationData in SubmitData class. But I can't receive that emmited signal myTimeout().

    In LocationData.h,
    static MyUtil *util;

    My connect statment in SubmitData.cpp as under.
    connect(LocationData::util, SIGNAL(locationTimeOut()), this, SLOT(cancelProgress()));

    MyUtil.cpp
    void MyUtil::locTimeout()
    {
    QMessageBox mb;
    mb.setText("Timer Matured");
    mb.setStandardButtons(QMessageBox::Ok);
    mb.exec();
    emit locationTimeOut();
    }
    Anyone has idea why it's not working??
    Is this problem due to static object??

    Thanks.
    Last edited by smehta_ce; 2010-05-02 at 01:07.

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Receiving signal of static object

    First thing to do is to verify that the "util" pointer is indeed set at the time you do the connect() (eg, with a Q_ASSERT). (Note that you should use some sort of test, eg, a method call, that assures that the pointer isn't simply garbage.) Also capture the return code of the connect() and check it (again, with a Q_ASSERT).

    I'm betting you either haven't initialized your pointer or you've got a simple spelling error in the SIGNAL or SLOT parm.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    43

    Unhappy Re: Receiving signal of static object

    Hi Thanks for reply, I am initializing my util pointer in LocationData constructor with util=new Util(); It is properly working for other QTime related functions. My SubmitReport.cpp and Util.cpp as under.

    SubmitReport.cpp

    SubmitReport::SubmitReport(QWidget *parent) :
    QWidget(parent)
    {
    ui.setupUi(this);
    nInterface = new NetworkInterface();
    progressDialog = new QProgressDialog("Acquiring Data....", "Cancel", 0, 0, this, 0);
    connect(ui.submitButton, SIGNAL(clicked()), this, SLOT(saveDescription()));
    connect(LocationData::util, SIGNAL(locationTimeOut()), this, SLOT(noAddressRetrived()));// Not Working
    }

    void SubmitReport::saveDescription(void)
    {

    QMessageBox mb;
    mb.setText("Timer Active=" + QString ::number(LocationData::util->timerId()));// Working Propely
    mb.setStandardButtons(QMessageBox::Ok);
    mb.exec();
    if(LocationData::util->timerId() != -1)
    {
    progressDialog->exec();
    }
    QString data = ui.descriptionText->toPlainText();
    HashData::description = data;
    CreateTextFile* txtFile = new CreateTextFile();
    bool isFileGen = txtFile->generateFile();
    //QMessageBox mb;
    mb.setText("Text Data" + data);
    mb.setStandardButtons(QMessageBox::Ok);
    mb.exec();
    if (isFileGen == true)
    {
    nInterface->sendToFtp();
    }
    }

    void SubmitReport::noAddressRetrived()
    {
    progressDialog->hide();
    QMessageBox mb;
    mb.setText("Cannot Retrieve Address. Please Enter Manually and Submit Again");
    mb.setIcon(QMessageBox::Warning);
    mb.setStandardButtons(QMessageBox::Ok);
    mb.exec();
    ui.locationText->setEnabled(true);
    ui.locationText->setFocus();

    }
    SubmitReport::~SubmitReport()
    {

    }

    Util.cpp
    Util::Util()
    {
    locTimer = new QTimer();
    connect(locTimer, SIGNAL(timeout()), this, SLOT(locTimeout()));
    }

    void Util::startLocationTimer()
    {
    QMessageBox mb;
    mb.setText("Timer start");
    mb.setStandardButtons(QMessageBox::Ok);
    mb.exec();
    locTimer->start(5000 * 60);
    }

    void Util::stopLocationTimer()
    {
    QMessageBox mb;
    mb.setText("Timer Stoped");
    mb.setStandardButtons(QMessageBox::Ok);
    mb.exec();
    locTimer->stop();
    }

    bool Util::locationTimerActive()
    {
    QMessageBox mb;
    mb.setText("In timer Active--" + locTimer->isActive());
    mb.setStandardButtons(QMessageBox::Ok);
    mb.exec();
    return locTimer->isActive();
    }

    int Util::timerId()
    {
    QMessageBox mb;
    mb.setText("Timer Id" + locTimer->timerId());
    mb.setStandardButtons(QMessageBox::Ok);
    mb.exec();
    return locTimer->timerId();
    }

    void Util::locTimeout()
    {
    QMessageBox mb;
    mb.setText("Timer Matured");
    mb.setStandardButtons(QMessageBox::Ok);
    mb.exec();
    emit locationTimeOut();
    }
    Util::~Util()
    {

    }

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Receiving signal of static object

    Basically, danhicksbyron is correct the most likely. Either it's misspelling in signal/slot name or you initialize variable after trying to connect. qobject_cast will return zero, if pointer is a wild pointer or pointing to some other class.
    However, using static variables is a bad idea in general.

  5. #5
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Receiving signal of static object

    I don't see where you're initializing util. I don't see where you're constructing LocationData. Try some asserts.

Similar Threads

  1. Creating a static method will not work
    By FrankTheFox in forum Symbian
    Replies: 6
    Last Post: 2009-09-21, 14:38
  2. sending and receiving AT GSM commands
    By ervalerio in forum Mobile Java General
    Replies: 2
    Last Post: 2008-10-13, 14:08
  3. Application startup fails in N72, static initialization is to blame ?
    By kamanashisroy in forum Mobile Java General
    Replies: 2
    Last Post: 2008-06-18, 08:23
  4. Page builder
    By giogiogio in forum Symbian
    Replies: 2
    Last Post: 2007-08-26, 18:08
  5. Nokia 3330 - Receiving no Signal
    By dazzer_2000 in forum General Development Questions
    Replies: 0
    Last Post: 2003-03-22, 12:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×