Solved Question about Qcombo box < crash issue
-
@VRonin this is the only information I can find, is this of any help??
1 ZeqRK7QStringS1_ 0x68aed806 2 ?? 0x2d630a0 3 ??
-
This addItem code is for a different QComboBox then in your original post (baudRateBox instead of serialPortBox). What is the addItem code for serialPortBox? The second parameter of addItem() is the UserRole data that will be retrieved by itemData() (by default, you can select a different role if you want, however).
-
I have more combo boxes, it was just an example of how I put things in them
-
@bask185 You need to build and run the debug version in order to get the stack trace with detailed information. If you do this and then post that information we can tell you where your crash is.
Based on the release stack trace you are crashing in QString. We don't know where yet but if you repost the debug build stack trace we will. It should tell us line and file.
-
ASSERT failure in QList<T>::operator[]: "index out of range", file ../../../Qt5.7.0/5.7/gcc_64/include/QtCore/qlist.h, line 545
index out of range issue it seems, I verified that z is always within the range (0-2)
1 __GI_raise raise.c 54 0x7ffff5b81428 2 __GI_abort abort.c 89 0x7ffff5b8302a 3 QMessageLogger::fatal(const char *, ...) const 0x7ffff653ff4e 4 qt_assert_x(const char *, const char *, const char *, int) 0x7ffff653b821 5 QList<QString>::operator[] // << this the one qlist.h 545 0x427f8d 6 Setup::on_serialPortBox_activated setup.cpp 115 0x424c04 7 Setup::qt_static_metacall moc_setup.cpp 116 0x4297aa 8 Setup::qt_metacall moc_setup.cpp 183 0x4299ee 9 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff6746700 10 QComboBox::activated(QString const&) 0x7ffff77d4c65 11 ?? 0x7ffff77d6126 12 ?? 0x7ffff77d88e9 13 ?? 0x7ffff77de91d 14 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff6746056 15 ?? 0x7ffff77d528b 16 QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject *, QEvent *) 0x7ffff671e853 17 QApplicationPrivate::notify_helper(QObject *, QEvent *) 0x7ffff76dc505 18 QApplication::notify(QObject *, QEvent *) 0x7ffff76e3808 19 QCoreApplication::notifyInternal2(QObject *, QEvent *) 0x7ffff671eae0 20 QApplicationPrivate::sendMouseEvent(QWidget *, QMouseEvent *, QWidget *, QWidget *, QWidget * *, QPointer<QWidget>&, bool) 0x7ffff76e27bf ... <More>
-
problem looks to be in:
ui->descriptionLabel->setText(list[z]);
almost surely becauselist
is empty as I never saw you setting the user role to a QStringList anywhere in your code -
@VRonin that is probably because I cannot find the words 'user' or 'role' anywhere on the doc.qt page and I don't understand how I can succesfully use a QStringClass for my purpose.
@all Nobody knows how I can display the description of my serial port???
-
@bask185 said in Question about Qcombo box < crash issue:
I cannot find the words 'user' or 'role' anywhere on the doc.qt page
😕 http://doc.qt.io/qt-5/qcombobox.html#insertItem
Nobody knows how I can display the description of my serial port???
we do and we tried to explain you how. you have to save it in the data of the combobox
-
@VRonin I was looking on the QStringList page ...
I was doing that in an other function
for (QSerialPortInfo &info : infos) { QStringList list; list << info.portName(); ui->serialPortBox->addItem(list.first(), list); }
So I was stuffing port names in the combo box, but not the description because that is not what I want. The descriptions are to be printed under the combobox in a text label.
So that function made me thinking, I made a new private QStringList variable called 'list2' and in the same function in which I fill the combobox I also fill 'list2' with dem descriptions
for (QSerialPortInfo &info : infos) { QStringList list; list << info.portName(); list2 << info.description(); // < new line ui->serialPortBox->addItem(list.first(), list); }
so now I only had to do.
void Setup::on_serialPortBox_activated(const QString &arg1) { z = ui->serialPortBox->currentIndex(); ui->descriptionLabel->setText(list2[z]); }
And voila:
-
not how I would have done it but good enough for rock and roll
P.S.
I'd have done:for (const QSerialPortInfo &info : infos) ui->serialPortBox->addItem(info.portName(), info.description());
and then, in the constructor, added:
connect(ui->serialPortBox,static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),[this](){ui->descriptionLabel->setText(ui->serialPortBox->currentData().toString();});
no need for QStringLists
-
dat looks rather.. exremely complicated compared to what I did O.o vague C++ syntax sometimes. Besides I really must avoid the use of pointers whenever possible, pointers are not good for my mental health -_-*
-
-
@bask185 said in Question about Qcombo box < crash issue:
Besides I really must avoid the use of pointers whenever possible, pointers are not good for my mental health
Lol, you may want to consider something other than C++. ;) I felt that way when I was first learning, but if you continue to feel that way, you really need a language that does it for you. Java, C#, python, tons of options. Python will even let you use Qt. :)
-
I was having a perfectly fine working application in processing. I shook dat code right out of my sleeve. Easy OO programming, no difficult vague words such as 'public' or 'private', no pointers, some easy global variables which I can use in every class I make. Truly processing is by far the easiest program ever :D
And do you know what it takes to export an application to Linux? Ctrl shift E, check Linux, press Export applications and BAM it works! Java ftw! But.... app was too heavy for my rpi... freakin java -_-". Now it takes me more than a week to crosscompile for the rpi. I had to install ubuntu on my Pc to find out I had only one 1GB space left so I had to delete my windows OS.... I do kinda regret I did not learn python and Tkinter first...
But the things I learn.. priceless
-
@bask185 Yea java is just so slow and heavy. That's why I could never get into it.
I use an ide (CLion) that is written in java and it is so slow compared to the other one I use that is written in C++ (slickedit). I like CLion's features, but the java engine is just so slow. It's almost unusable on large projects, meanwhile slickedit has no speed issues.
Another anecdote.. I spun up an AWS micro server the other day to run upsource from jetbrains. It needed > 2GB in RAM just to start the application because of the java and cassandra dependency. If I wrote a similar application to upsource in something faster like C++ it would take maybe 50mb to start, not >2gb, lol. I killed the AWS server as I didn't want to pay for the bigger server just to mess around with upsource and installed it locally on a server in my office.
Morale of the story, java is great for easy, it does everything for you, programming, but it is awful when it comes to actually using the software that is produced, lol.