tags:

views:

34

answers:

2

i am using QT4 for my c++ programme i want to enable a SIGNAL automatically when my window is open so please tell me how do i enable a SIGNAL when my programme window open.

i am new to QT so please give a detail description.

Thanks

+1  A: 

Hi.

You may rewrite public function show in you class, for example:

mainwindow.h

class MainWindow : public QMainWindow {
    Q_OBJECT;
public:
    MainWindow();

    void myShow() {
        activateWindow();
        show();
        emit mySignalFunc();
    }
signals:
    void mySignalFunc() {
        qDebug() << "Here is my signal!!!";
    };
};

main.cpp in main() function:

MainWindow wnd;
wnd.myShow();

Good luck!

mosg
It's bad idea. There is QWidget::showEvent() protected virtual function which should be reimplemented. One of disadvantages of your example: there are two functions "show()" and "myShow()" doing the same and available in this class but you need to remember (and make other team members to remember) to use only "myShow()".
VestniK
@VestniK I know that, and I think that jopa right, and it's the right way to move when we reimplement QWidget::showEvent() function, BUT! I can read and *i am new to QT so please give a detail description* saying, at least for me, that this method is too complex for Peeyush. VestniK, did you learned C++, Qt or what ever with the end of the books? :) Nothing personal.
mosg
@mosg I gave you detailed explanation why I think that it's bad idea to follow your advise. Regardless of Peeyush knowledge in Qt I do believe he will be able to reimplement one protected virtual function. I do believe as well that from the very beginning one should learn best practices. I think your advise is good only as kludge in case if there is no other way to implement such feature because it may lead to bugs which hard to investigate. I put -1 to your answer because I really think that it's bad answer. Don't take it personally.
VestniK
+2  A: 

Overwrite QWidget::showEvent() (see QT documentation)

jopa