Results 1 to 2 of 2

Thread: Qtscript -signals and slots

  1. #1
    Join Date
    Jul 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question Qtscript -signals and slots

    Hi all,
    I have just started programming using Qt4.4.
    I was trying the example given in
    http://labs.trolltech.com/blogs/2007...ctions-from-c/
    The only thing I have changed here is that I have defined a class MyWindow which incorporates the window,awakenButton and exitButton.
    I was successful in connecting javascriptfile using a signal(buttonClicked()) defined in MyWindow class to a javascript file using
    qScriptConnect(obj1, SIGNAL(buttonClicked()), object, slot);
    obj1-object of MyWindow.

    I want to connect to a signal defined in MyWindow class from javascript file and emit this signal in the same scriptfile so I tried using the syntax given in QtScript Module (Qt4.4)but it didnt work. Is there any specific way to connect to a signal from scriptfile?

    Also,once the connection is established, can we initialize objects in scriptfile like
    var obj2=new MyWindow;
    I tried this but this also wasnt working.
    Is this possible and is this the right way?

    Thnx in advance.

  2. #2
    Join Date
    Jul 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qtscript -signals and slots

    Hi again folks...
    I am just giving you an idea of MyWindow class..

    Qt Code:
    1. /********************MyWindow.h************************/
    2. class MyWindow: public QObject,public QScriptable
    3. {
    4. Q_OBJECT
    5. public:
    6. Window();
    7.  
    8. public slots :
    9. void changeButton();
    10. void clickEvent();
    11. void changeSumthing();
    12. void getexitButton();
    13.  
    14.  
    15.  
    16. private:
    17. QWidget window;
    18. QPushButton *awakenButton;
    19. QPushButton *exitButton;
    20. signals:
    21. void buttonClicked();
    22.  
    23. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. /****************main.cpp********************/
    2. int main(int argc, char **argv)
    3. {
    4. QApplication app(argc, argv);
    5. MyWindow *window1=new Window;
    6. QScriptEngine engine;
    7. QScriptValue object = engine.newObject();
    8. object.setProperty("name", QScriptValue(&engine, "Megatron"));
    9. QFile file("window.js");
    10. bool t=file.open(QIODevice::ReadOnly);
    11. QScriptValue slot = engine.evaluate(file.readAll());
    12. QString str=slot.toString();
    13. file.close();
    14. //connecting to scriptfile using signal buttonClicked(emitted in clickEvent()slot )
    15. qScriptConnect(window1, SIGNAL(buttonClicked()), object, slot);
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 
    Lastly my window.js file is:
    javascript Code:
    1. /*********window.js************/
    2. return function() {
    3. var sender = __qt_sender__;
    4. sender.value=1;
    5. sender.changeButton();
    6. //tried connecting the exitButton click signal to the slot changeSumthing..but not working
    7. sender.exitButton.clicked.connect(sender,"changeSumthing");
    8. //Also can we initialize objects here..and then access the methods
    9. var obj2=new MyWindow;
    10. }
    To copy to clipboard, switch view to plain text mode 
    I hope this will help u to understand my problem better..
    Last edited by jacek; 25th July 2008 at 23:40. Reason: missing [code] tags

Similar Threads

  1. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  2. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 01:45
  3. Signals and Slots Across Threads
    By themusicalguy in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2007, 11:16
  4. signals and slots in plugins
    By anderl in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 13:57
  5. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12

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.