On 3 May 2018, at 5:05 pm, J Barchan <jnbarchan at gmail.com> wrote:
>>>> On 3 May 2018 at 16:17, Phil Thompson <phil at riverbankcomputing.com> wrote:
> On 3 May 2018, at 3:22 pm, J Barchan <jnbarchan at gmail.com> wrote:
> > Hey Phil,
> >
> > Assuming I am not barking up the wrong tree, I see you yourself were discussing this issue in http://python.6.x6.nabble.com/PyQt5-NULL-QVariant-tp5188782p5190811.html. It includes:
> >
> > > Can you confirm that returning empty string and 0 for NULL is expected
> > > behavior and not seen as a bug?
> >
> > Yes. If you want to distinguish null QVariants then use sip.enableautoconversion(). The problem is that you are not willing to do that.
> >
> > So I'm bumbling around trying to put a sip.enableautoconversion() in! Trouble is, I don't understand the syntax, and I don't know where to put it (I'm not finding any examples, and you two obviously knew more than me about it :) )
> >
> > 1. I'm assuming I want to suppress converting QVariants. I'm trying
> > ​​sip.enableautoconversion(QVariant, False)
> > but it doesn't know what QVariant is, and I don't know if it's supposed to or my syntax or imports or whatever?
>> ​​Import QVariant from QtCore.
>> > 2. I don't know where I'm supposed to disable & re-enable the autoconversion? My method is an override called implicitly by Qt.
> > * Is this a "directive" that's supposed to be used e.g. as a Python method is read in, and so belongs around the whole function?
> > * Is this a "run-time* that I just need to put inside my method overload around where it calls the base class method? Or by the time it has hit my overload is it too late because some conversion has already happened?
> > * Do I actually need to ​​put it around the whole of my top-level call to, say, QSqlQueryModel.rowCount(), which is what (I understand to be) invoking calls to the overridden QSqlQueryModel.data() method?
>> ​​I think you need to do the latter - at least as a workaround for the moment. I ​​need to add a directive to SIP to disable the auto-conversion during the code that handles the virtual and calls the Python re-implementation.
>> Phil
>> ​Hi Phil,
>> Right, I think we're in business, here goes...!​
>> First, I took your *original* response of "No and no." to indicate that my issue would have nothing to do with PyQt. In the end I think we are agreeing it has turned out to be a PyQt issue after all.
>> Second, yes, I figured "​Import QVariant from QtCore" was what I was missing. (Not helped by PyCharm warning me it really wanted a "sip wrappertype" for sip.enableautoconversion() instead of a "type", but it works OK at run-time.) I actually interpreted http://pyqt.sourceforge.net/Docs/PyQt5/pyqt_qvariant.html:
>> v2 (the default for Python v3) does not expose the QVariant class to Python
>> ​as meaning that QVariant was not going to be defined/exported in any PyQt file​ at all. But I see it still is.
>> Third, in view of your "​I think you need to do the latter [​put ​sip.enableautoconversion() around the whole of my top-level call] - at least as a workaround for the moment.", I started out doing that. However, I found that the data() method is being called all over the place (e.g. throughout the QTableView displaying the model), which I guess makes sense, so that was soon a non-starter. In any case it would be way-dangerous to have to change QVariant behaviour across a large area of code. I would hugely prefer to only have to do so across the call to the base method from the derived method, and to my pleasure it seems to be working just fine like that. So my override (to give you a flavor of why I need it) now actually reads:
>> def data(self, index: QtCore.QModelIndex, role=QtCore.Qt.DisplayRole) -> typing.Any:
> DBModelCommon.dataIndexIsValid(index) # do some checking that index is valid
>> import sip
> sip.enableautoconversion(QtCore.QVariant, False)
> value = super().data(index, role) # wrap call to QSqlQueryModel.data() inside no-convert-QVariant-to-Python
> sip.enableautoconversion(QtCore.QVariant, True)
>> return DBModelCommon.dataValue(value, role) # do some (potential) post-processing on the value returned
A more resilient version would be...
was_enabled = sip.enableautoconversion(QtCore.QVariant, False)
...
sip.enableautoconversion(QtCore.QVariant, was_enabled)
> ​You will understand this better than I, but the implication is that the problem is not in my own Python definition of this override itself already doing a conversion and going wrong, but rather at the time it calls the base function and grabs its return value into Python?
>> So far all I can say is that from what i have seen it now handles my values --- both NULLs and non-NULLs --- ​correctly! :)
> Finally, I'm interested to understand what is going on here, and why you "​need to add a directive to SIP to disable the auto-conversion during the code that handles the virtual and calls the Python re-implementation".
As you have shown it is not necessary in this case. However you would have problems for virtual re-implementations that are passed a QVariant as an argument rather than being passed back as a result.
> I'm assuming the override was returning a QVariant-converted-to-Python-type, then something about other (Qt) C++ code calling the override and not being happy about the return type, or something? So how do you (or I) know whether there are going to be other cases (overrides) which, say, return or pass or receive a QVariant (which could be a NULL one), and will also fall foul of this issue? Do you/I need to look through every Qt function? Have you already done this and are confident that there can be only a few remaining which you have not spotted? Is that how it works?
Very few contexts in Qt care about null QVariants - this may well be the only one. (An invalid QVariant - which mapped to None - is much more common.)
Phil
More information about the PyQt
mailing list
¡®She has never mentioned her father to me. Was he¡ªwell, the sort of man whom the County Club would not have blackballed?¡¯ "We walked by the side of our teams or behind the wagons, we slept on the ground at night, we did our own cooking, we washed our knives by sticking them into the ground rapidly a few times, and we washed our plates with sand and wisps of grass. When we stopped, we arranged our wagons in a circle, and thus formed a 'corral,' or yard, where we drove our oxen to yoke them up. And the corral was often very useful as a fort, or camp, for defending ourselves against the Indians. Do you see that little hollow down there?" he asked, pointing to a depression in the ground a short distance to the right of the train. "Well, in that hollow our wagon-train was kept three days and nights by the Indians. Three days and nights they stayed around, and made several attacks. Two of our men were killed and three were wounded by their arrows, and others had narrow escapes. One arrow hit me on the throat, but I was saved by the knot of my neckerchief, and the point only tore the skin a little. Since that time I have always had a fondness for large neckties. I don't know how many of the Indians we killed, as they carried off their dead and wounded, to save them from being scalped. Next to getting the scalps of their enemies, the most important thing with the Indians is to save their own. We had several fights during our journey, but that one was the worst. Once a little party of us were surrounded in a small 'wallow,' and had a tough time to defend ourselves successfully. Luckily for us, the Indians had no fire-arms then, and their bows and arrows were no match for our rifles. Nowadays they are well armed, but there are[Pg 41] not so many of them, and they are not inclined to trouble the railway trains. They used to do a great deal of mischief in the old times, and many a poor fellow has been killed by them." As dusk came on nearly the whole population of Maastricht, with all their temporary guests, formed an endless procession and went to invoke God's mercy by the Virgin Mary's intercession. They went to Our Lady's Church, in which stands the miraculous statue of Sancta Maria Stella Maris. The procession filled all the principal streets and squares of the town. I took my stand at the corner of the Vrijthof, where all marched past me, men, women, and children, all praying aloud, with loud voices beseeching: "Our Lady, Star of the Sea, pray for us ... pray for us ... pray for us ...!" It had not occurred to her for some hours after Mrs. Campbell had told her of Landor's death that she was free now to give herself to Cairness. She had gasped, indeed, when she did remember it, and had put the thought away, angrily and self-reproachfully. But it returned now, and she felt that she might cling to it. She had been grateful, and she had been faithful, too.[Pg 286] She remembered only that Landor had been kind to her, and forgot that for the last two years she had borne with much harsh coldness, and with a sort of contempt which she felt in her unanalyzing mind to have been entirely unmerited. Gradually she raised herself until she sat quite erect by the side of the mound, the old exultation of her half-wild girlhood shining in her face as she planned the future, which only a few minutes before had seemed so hopeless. After he had gloated over Sergeant Ramsey, Shorty got his men into the road ready to start. Si placed himself in front of the squad and deliberately loaded his musket in their sight. Shorty took his place in the rear, and gave out: The groups about each gun thinned out, as the shrieking fragments of shell mowed down man after man, but the rapidity of the fire did not slacken in the least. One of the Lieutenants turned and motioned with his saber to the riders seated on their horses in the line of limbers under the cover of the slope. One rider sprang from each team and ran up to take the place of men who had fallen. "As long as there's men and women in the world, the men 'ull be top and the women bottom." Then, in the house, the little girls were useful. Mrs. Backfield was not so energetic as she used to be. She had never been a robust woman, and though her husband's care had kept her well and strong, her frame was not equal to Reuben's demands; after fourteen years' hard labour, she suffered from rheumatism, which though seldom acute, was inclined to make her stiff and slow. It was here that Caro and Tilly came in, and Reuben began to appreciate his girls. After all, girls were needed in a house¡ªand as for young men and marriage, their father could easily see that such follies did not spoil their usefulness or take them from him. Caro and Tilly helped their grandmother in all sorts of ways¡ªthey dusted, they watched pots, they shelled peas and peeled potatoes, they darned house-linen, they could even make a bed between them. HoMEÒ»¼¶Ã«Æ¬ÊÓÆµÃâ·Ñ¹«¿ª
ENTER NUMBET 0018vip724.com.cn consts.com.cn www.dshijdksds.com.cn www.richtiger.com.cn www.17gongyi.com.cn www.mjqa.com.cn www.seubbs.com.cn www.xjqg.com.cn fsqiyi.com.cn kmpaige.com.cn