[Python] limiting value for int in pyqtSignal?

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    I have a signal which looks like this:

    add_history_row_signal = QtCore.pyqtSignal(int, int)


    The first int is a key for a dict, to retrieve a value. And in fact this int is the object id of a given object (i.e. id(my_object)).

    The connected method gets the int value ... but it is wrong, and the key is then not found in the dict.

    However, if I make the int used as a key smaller (losing the guarantee of uniqueness), it works OK:

    he_id_val = id(history_entry) % 10000
    ...
    self.he_id_to_row_map[he_id_val] = [date_item, entry_item]
    self.add_history_row_signal.emit(he_id_val, len(history_list))


    ... these 2 ints then come through OK to the connected method

    I could only think of 2 explanations for this: either there is a maximum value for the int key of a dict in Python (this doesn't appear to be the case as far as I can tell), or a pyqtSignal appears to impose some sort of "MAX INT" limitation.

    I have searched on this and found nothing. Obviously Qt is written in C++, and this max int value appears to be 2147483647. A typical value from id(x) in Python code is 1715560796288, so larger.

    Is there any known way to specify that a PyQt signal is using a C++ long rather than a C++ int?

    An obvious workaround is to convert this id value to a string. Just wondered if I can avoid this.

    Continue reading...

Compartilhe esta Página