0

When QLineEdit() is used in text it appears to create a bug in lists and dictionaries,this code works:

from PyQt5.QtWidgets import *
a=[1,2]
b=a[0]
print(b)

but when a line edit is added python will crash

from PyQt5.QtWidgets import *
c=QLineEdit()
a=[1,2]
b=a[0]
print(b)

I have found this when using the Anaconda package on multiple computers, can anyone suggest a work around which does not involve not using lists or dictionaries.

2
  • 2
    Do you get error message ? Always add full error message (traceback) in question. Commented Oct 31, 2016 at 20:37
  • Please read the guidance on providing a minimal reproducible example. Commented Oct 31, 2016 at 22:24

1 Answer 1

0

You use it in wrong way. First you have to use QApplication(sys.argv) which initiates all needed modules and librares.

from PyQt5.QtWidgets import *
import sys

app = QApplication(sys.argv)

c = QLineEdit()
a = [1,2]
b = a[0]
print(b)

So find some PyQt5 tutorial.


EDIT: problem is not list or dictionary but QListEdit (or any other Widget) without QApplication

You get the same problem in

from PyQt5.QtWidgets import *
QLineEdit()

or

from PyQt5.QtWidgets import *
QWidget()
Sign up to request clarification or add additional context in comments.

4 Comments

This was just a demonstration as It was an issue I found in a program about 500 lines long and the line edit was not intended to do anything but it does cause the error with lists and dictionaries.
You get the same error without lists and dictionars too. Problem is not list or dictioarny but QListEditor without QApplication.
The error was occurring in a full program with QApplication and no in console error message but as I would prefer not to post the program due to plagiarism checks I understand it would be very difficult for you to help. I did not realise due to this that it was a separate issue. Thanks anyway.
Maybe they put QListEditor in wrong place. If it is open source code then maybe you should send information to author.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.