Its simple as it can be, but I cant do it.
I have txt file which contains name,surname, mail and telephone number like that:
name surname phone mail
name surname phone mail
name surname phone mail
Everything is seperated with tabs and after the mail there is newline at the end of each line
Now I want to search the file for the specific name im searching and to show the results when I click the button Search in TableWidget (using python Qt).
Its simple, but I have some errors I cant resolve.
Thanks for the help.
You have two possible steps to accomplish here.
To get your started, a simple and straightforward approach for reading in your data would be to use the csv module. You could also create a custom table model that would read directly from a csv file, but I think thats beyond our level right now.
Here is a simple way to get your text file into a data structure:
Now people will contain all your lines in the form: (name, surname, email)
From here, you can populate your TableWidget. This is a really basic snippet that should give you the idea:
The colCount is just a little protection in case you have unbalanced amounts of fields on each line. Again this is just a general approach.
From here its a little open ended as to how you want to do the search. But what you could do is connect you search button to a method that handles the search. Keep in mind I am writing all this as just global functions. You would probably have your class, and be using
selfeverywhere. But I am keeping it short and simple: