Results 1 to 4 of 4

Thread: QAxScriptManager not returning a QAxScript* for VBScript

  1. #1
    Join Date
    Aug 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QAxScriptManager not returning a QAxScript* for VBScript

    Hi,

    I'm trying to call a VBScript from within Qt and set up a small test application:

    Qt Code:
    1. #include <QAxScriptManager>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QAxScriptManager m_manager;
    7. QAxScript *m_helloWorld = m_manager.load("C:\\test.vbs", "HelloWorld");
    8. if (m_helloWorld)
    9. m_helloWorld->call("helloWorld");
    10. else
    11. qDebug() << "didn't load";
    12. }
    To copy to clipboard, switch view to plain text mode 

    The VBScript is at the right place on C:\test.vbs and looks like this:

    Qt Code:
    1. Function helloWorld()
    2. msgbox("Hello World")
    3. End Function
    To copy to clipboard, switch view to plain text mode 

    Now when I compile and run this I don't get a QAxScript back from the QAxScriptManager. Stepping through the code I learned that the file is read and a QAxScript object created, but in the load function on it its isValid() function returns false because the internal member 'engine' is not set and therefore later the object is discarded and a NULL pointer returned. But I couldn't find where 'engine' would ever be set.

    Can you please help me understand what I am doing wrong?
    Or give me some example code?

    Cheers
    Jan

    Edited: typo

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QAxScriptManager not returning a QAxScript* for VBScript

    QAxScriptManager::registerEngine() looks promising (a guess, not from experience). I don't know exactly what you would send it, but I would try:
    Qt Code:
    1. QAxScriptManager::registerEngine("vbs", "VBScript");
    To copy to clipboard, switch view to plain text mode 
    where "VBScript" is the ProgId of the VBSCript in process server.

  3. #3
    Join Date
    Aug 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAxScriptManager not returning a QAxScript* for VBScript

    Nope, that didn't do the trick. I changed my code to look like this and scriptEngineLoaded is set to true, but the result is still the same. Also from the Qt code I read I believe the VBScript engine is set automatically internally when a script ending in vbs is loaded.

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. bool scriptEngineLoaded = QAxScriptManager::registerEngine("VBScript", "vbs");
    4. QAxScriptManager m_manager;
    5. QAxScript *m_helloWorld = m_manager.load("C:\\test.vbs", "HelloWorld");
    6. if (m_helloWorld)
    7. m_helloWorld->call("helloWorld");
    8. else
    9. qDebug() << "didn't load";
    10. }
    To copy to clipboard, switch view to plain text mode 


    Added after 47 minutes:


    Ah, I found some very uselful documentation on http://crpppc19.epfl.ch/doc/qt4-doc-...container.html and after reading through the testcon example http://crpppc19.epfl.ch/doc/qt4-doc-...t-testcon.html (find the code in your qt installation directory under tools/activeqt/testcon) I got it working.

    Qt Code:
    1. #include <QAxScriptManager>
    2. #include <QDebug>
    3. #include <QWidget>
    4. #include <QApplication>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. // Some QObject is crucial. If the script manager is not initialized with a QObject* then call() will return "Unknown Error"
    11. QWidget *widget = new QWidget();
    12. QAxScriptManager *m_manager = new QAxScriptManager(widget);
    13.  
    14. QAxScript *m_helloWorld = m_manager->load("C:\\test.vbs", "HelloWorld");
    15. if (m_helloWorld)
    16. m_helloWorld->call("helloWorld()"); // don't forget () for a function without params.
    17. else
    18. qDebug() << "didn't load";
    19.  
    20. // cleanup code missing
    21. return a.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    Edited: removed doubled part of post
    Last edited by jgirlich; 24th May 2013 at 09:25.

  4. #4
    Join Date
    Aug 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAxScriptManager not returning a QAxScript* for VBScript

    To specify: Since the test function in the vbs file used MsgBox a QWidget was needed. If you don't use any GUI elements in your vbs code you can skip the QWidget and it works fine as well.

Similar Threads

  1. QAxScriptManager
    By virus in forum Newbie
    Replies: 0
    Last Post: 22nd March 2011, 14:33
  2. Returning const &
    By frenk_castle in forum Newbie
    Replies: 2
    Last Post: 24th November 2009, 07:01
  3. zoomRectangle returning null
    By Raghaw in forum Qwt
    Replies: 0
    Last Post: 3rd November 2009, 12:52
  4. SelectFile() is returning NULL
    By abhilashajha in forum Qt Programming
    Replies: 6
    Last Post: 10th June 2009, 11:30
  5. returning a string
    By mickey in forum General Programming
    Replies: 2
    Last Post: 3rd February 2008, 19:41

Tags for this Thread

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.