Forum Discussion

Felixg's avatar
Felixg
Occasional Contributor
6 years ago

Problem calling method of custom qt object with QMetaObject::invokeMethod

Hi Everyone,

 

I am testing a Qt application with Test Complete, my context is :

  •  Application compiled with Qt 5.9.5 + MSVC 2015 64 bit
  • Test Complete 12.50 with VBScript language
  • In this example case, my application is only a QWidget with a QPushButton. When clicking on this button, a custon menu appears.
  • This menu is a class CMenu, derived from QMenu
  • CMenu is declared in object mapping under Qt Controls > Menu in Test Complete project properties (default and current)

 

My need is : access some data of my CMenu.

 

These data are in a QList<QString> private member of my CMenu class.

So, I declared a public accessor in my class to get one item of my list by its index in the list.

 

...
class CMenu : public QMenu
{
    Q_OBJECT

private:
    QList<QString> m_lstTestNames;

public:
...
    Q_INVOKABLE QString getTestName(int index) const;
...
};

...

QString CMenu::getTestName(int index) const
{
    return this->m_lstTestNames.at(index);
}

It works fine, in the object browser of Test Complete, I found my object and this method

  • Sys.Process("proto_cmenu").QtObject("CMenu", "", 1).getTestName
  • Description : Function getTestName(Param1 as Integer) as Object

 

Now I want to use this method in my test script. So, first I open my application and I click on the push button to display my menu, and then call my method like below for example (it's the line 46 of my script) :

 

Log.Message "Test Name 0 = " & Sys.Process("proto_cmenu").QtObject("CMenu", "", 1).getTestName(0)

 

My problem is :

 

  • I got the following error :

VBScript runtime error.

Erreur non spécifiée

Error location: Unit: "FELIX\FLX_TST_007\Script\MAIN" Line: 46 Column: 2.

 
  • With the following message just above in the log :

Debug String: QMetaObject::invokeMethod: No such method CMenu::getTestName(getTestName)
Candidates are:
    getTestName(int)

I don't understand this message, as you see above, I called my function with an integer in my script, why does it talk me about "CMenu::getTestName(getTestName)" ?
Can someone give me some help to go through this problem ?

2 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    to call log.message you need parenthesis

    see this example.

    It's better to get the name first in to a string and then display it with .... log.message(str)

    • Felixg's avatar
      Felixg
      Occasional Contributor

      Hi NisHera,

       

      Thanks for your quick answer.

       

      So I tried :

       

      Dim str : str = Sys.Process("proto_cmenu").QtObject("CMenu", "", 1).getTestName(0)
      Log.Message ("Test Name 0 = " + str)

      Nevertheless, I get the same error :

       

      Debug String: QMetaObject::invokeMethod: No such method CMenu::getTestName(getTestName)
      Candidates are:
          getTestName(int)