Forum Discussion

ebodien's avatar
ebodien
Contributor
12 years ago

Qt Type Mismatch Error

I am trying evaluate whether a given string will fit in the space provided on the screen.  The application uses QT and the QT library has the methodQbounding_Rect.  It seems like the following should work:



sub Fit(Target)

'Target = Aliases.Viewer.MainWindow.centralwidget.swMain.pgMainScreen.frmMainControl.lblControl

log.message(Target.QWidget_fontMetrics.QFontMetrics_boundingRect_4(Target.QtText).width)

end sub



However I get a type mismatch error.  The QT help states that the paramber must be a QString which I thought was the QtText property.  Any suggestions would be appreciated.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Community,


     


    Can someone suggest Eero how to work with QString in TestComplete?


     

  • rgratis's avatar
    rgratis
    Frequent Contributor
    You may have already checked this, but I noticed in the QFontMetrics class references online that there are multiple variations of boundingRect.  Perhaps TestComplete is breaking them out as different methods (_1, _2, _3, and _4 as above).  I've noticed this happens with native Java methods sometimes in my application.  If so, i would guess the "_4" method is not the one that accepts the text parameter.

  • Thanks for the response.



    I did try the other boundingRect methods and they gave a different error, the error they gave was for the wrong number of parameters passed to the function so it looks like Rect_4 is the one I want. As far as I can determine:

    TC -> Qt

    boundingRect_3 -> boundingRect ( QChar ch ) const

    boundingRect_4 -> boundingRect ( const QString & text ) const

    boundingRect_5 -> boundingRect ( int x, int y, int width, int height, int flags, const QString & text, int tabStops = 0, int * tabArray = 0 ) const

    boundingRect_6 -> boundingRect ( const QRect & rect, int flags, const QString & text, int tabStops = 0, int * tabArray = 0 ) const
  • rgratis's avatar
    rgratis
    Frequent Contributor
    In that case, perhaps a generic string as returned by QtText is not interpretable as a QString.  You could use a native Qt method to obtain a QString and try that?





  • I'm not sure what you mean, could you give me an example?  Are you suggesting that I add a Qt method to the TestComplete Script or add a method to the Qt application that TestComplete will be able to access?
  • rgratis's avatar
    rgratis
    Frequent Contributor
    I was hoping you would able to access the native "text" property/field of the target control in TestComplete (versus Target.QtText).  Not sure if it would just be Target.text or it it would have some sort of prefix (QString_text?).  I don't have a QT app I could browse through here, so you'll have to scan through the Object Spy.



    If this is not the case, then yes, you could try to add a method or write some sort of function that would construct a QString object.  Always "interesting" trying to mix and match TestComplete scripting and native app methods...
  • Ah I understand now.



    I have tried using .Text instead of .QtText.  It gives me a different error: Object required instead of type mismatch.

  • rgratis's avatar
    rgratis
    Frequent Contributor
    My last idea here is trying the native namespace: Target.NativeQtObject.text.  Otherwise, putting the Object Browser into Advanced mode and scanning the list of Qt fields and methods for something that would return text.



    I took a look through the help topic on accessing native elements, and I don't really see anything there that would suggest that you can't access the native text property.http://support.smartbear.com/viewarticle/33170/





    Perhaps someone else has a few ideas?
  • Test complete really didn't like Target.NativeQtObject.Text, the error given was: Object doesn't support this property or method



    Using the object browser everything is fine, both the QtText and Text properties show the expected text. A log.message of Target.Text and Target.QtText both record the text the Qt Application is showing on the screen but for some reason the boundingRect_4 isn't playing nice.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Eero,


     


    QtText is TestComplete's property. It doesn't return QString. You need to initialize the QString object from the script and pass it to the method.