1

我正在开发一个函数,希望在给定的表格单元格中设置 QDateTimeEdit 对象的正确日期/时间。功能如下:

function setCalDateTime(iRow, month, day, year, hour, minute, ampm) {
// We get a handle to the cell containing the widDateTimeSelect
var cellOfInterest = waitForObject("{name='tbl_SourceInventory' type='QTableWidget' visible='1'}").cellWidget(iRow,3);
// We break apart the contents of the cell into its individual elements
var cellContents = object.children(cellOfInterest);
var tblModel = findObject("{type='QTableModel' unnamed='1'}");
// We search the contents of the cell for the QDateTimeEdit widget of interest.
for (var i = 0; i < cellContents.length; ++i) {
    if(typeName(cellContents[i]) == "QDateTimeEdit") {
        var dtString =  month + "/" + day + "/" + year + " " + hour + ":" + minute + " " + ampm;
        var dateTimeObj = QDateTime.fromString(dtString, "MM/dd/yyyy hh:mm AP");
        if(dateTimeObj.isNull() || !dateTimeObj.isValid()){
            test.fail("setDateTimeInDateTimeControl: Failed to create a valid datetime object");
        }else{
            cellContents[i].setDateTime(dateTimeObj);
        }
        break;
    }
  }
}

如果这看起来有点奇怪,那是因为我们使用的是 Froglogic 的 Squish for QT 工具包。我们使用 JavaScript 编写测试用例,但能够访问 QT 对象,从而调用这些对象上的公共函数和插槽。

如果我要创建一个测试用例,在该测试用例中我要获得一个包含在表中的 QDateTimeEdit 对象的句柄,那么上面设置新 QDateTime 对象的逻辑是有效的。如果我要调试上面的代码,那么所提供的功能就可以工作。

如果我只是运行测试,这个函数会失败cellContents[i].setDateTime(dateTimeObj);如果我查看调试文件,最突出的是以下内容:访问冲突 - 代码 c0000005。

感兴趣的两个问题: 1. 我应该如何最好地设置包含在表格单元格中的 QDateTimeEdit 对象。2. 为什么我在单步执行代码时可以设置正确的日期时间?

我当然感谢任何可能为我指明方向的指导。谢谢你。

4

1 回答 1

0

To answer question 2 first:

The main difference of going through the operations step by step is speed. Particularly, GUI applications constantly process events in the background. When giving the operations more time you may enable some important events to be processed. Like a full loading of your table. When accessing the cells in an intermediate phase you may be accessing an object that got deleted behind the test script's back.

The answer to question 1 may be related: your script is probably fine. But it may suffer from a race condition. I suggest to try whether adding a wait statement like snooze(3) makes the problem go away. That's note a permanent solution but if it helps other synchronization methods (e.g. waitFor()) can be employed.

于 2018-03-20T14:03:35.810 回答