Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.4k Topics 456.4k Posts
  • How do I update a row in the model and commit to database?

    Solved
    3
    0 Votes
    3 Posts
    206 Views
    JonBJ
    @jdent You do not need to drop down to accessing the model directly via QModelIndex and setData(). You can do it via the QSqlRecord. After you went rec.setValue(1, val); you need to call bool QSqlTableModel::setRecord(int row, const QSqlRecord &values) to transfer the altered in-memory rec to the model: QSqlRecord rec = tm.record(0); QModelIndex idx = tm.index(0, 3); qDebug() << rec.value(3).toString(); qDebug() << idx.data().toString(); auto val = rec.value(3).toString(); val += "###"; rec.setValue(3, val); qDebug() << rec.value(3).toString(); qDebug() << idx.data().toString(); tm.setRecord(0, rec); qDebug() << rec.value(3).toString(); qDebug() << idx.data().toString(); This shows the underlying model altered after the tm.setRecord(0, rec); statement. You can then commit() or whatever if you wish. record() generates a copy of what is in a model row. setRecord() is required if you alter that and want to write it back to the model row.
  • Missing CAP_NET_ADMIN permission.. REPOST

    Unsolved
    3
    0 Votes
    3 Posts
    467 Views
    JonBJ
    @gumtown Plenty of questions/solutions to this from Googling. See e.g. https://stackoverflow.com/questions/60989706/qt-bluetooth-stuck-when-connecting-to-classic-bluetooth-device You are trying to run your software as a non-root user. Try sudo setcap 'cap_net_raw,cap_net_admin+eip' yourapplication
  • QGraphicsView repeatedly updated when inserting thousands of QGraphicsItems

    Unsolved
    9
    0 Votes
    9 Posts
    821 Views
    JonBJ
    @wujie If your situation is " the same as yours [OP's]" then you are showing too many points, as several responders said. If you want to "add a batch of many items" you could temporarily detach the changed() slot as the OP wrote, or call blockSignals(). Having said that I'm not sure what the OP's actual issue was. While it is true that changed() would be called many times it is not true that each of these causes any visible update to the view. The view is only visually updated the next time the event loop is entered, at which time it should see so many updates that it does not do each one at a time but rather just decides to redraw the view a single time.
  • QTreeWidgetItem setBackground after stylesheet applied has no effect

    Solved
    5
    0 Votes
    5 Posts
    349 Views
    R
    @JonB Thank you for your reply. I will mark this thread as solved and try it out, thanks. Have a good one :)
  • 0 Votes
    4 Posts
    254 Views
    JonBJ
    @jdent No, there is no findId() or similar method, else you would see it on https://doc.qt.io/qt-6/qsqlrelationaltablemodel-members.html. If you wish to find it efficiently, e.g. if you have a thousand records in memory and don't want to search them sequentially each time, you can add a QSortFilterProxyModel on top of your QSql[Relational]TableModel, or sort the underlying model. Then if you set the sort to be by primary key you know the rows are in ascending primary ley order so you can use a binary search to find a given ID very fast. You do not need to use such an extra QSortFilterProxyModel for your view, you could just add it for the purpose of searching. You might get away without bothering to add one. Without a sort the statement will be SELECT * FROM table, with no ORDER BY clauses. Many/most SQL databases will deliver rows in primary key order when no ORDER BY is specified. If your ID column is the primary key they will appear in ID order (and so can be binary searched). However I would regard this as "fragile" as it relies on underlying SQL database behaviour. You could also impose a QSortFilterProxyModel and use its setFilter("id = ...") to pick out a given ID. However this does its work by issuing a SELECT ... WHERE id = ... against the table, not be searching rows already read in, and I don't think this is what you are looking for.
  • Debug version of libraries

    Unsolved
    2
    0 Votes
    2 Posts
    203 Views
    C
    You should ask whoever supplied the Qt libraries in the Windows cross-compilation environment on Linux that you are using. If you constructed this environment yourself then it is up to you to build Qt with relevant options.
  • Sorting list of structure based on specific ID parameter

    Unsolved
    7
    0 Votes
    7 Posts
    380 Views
    C
    @Christian-Ehrlicher The OP seems to want to add a series of consecutively numbered items to a list (the the number is "id"), remove arbitrary items, and have the items remaining still be consecutively numbered. Iterating over the list is solution to the question posed, but I think this is an XY Problem. This numbering: repeats information that is available simply from the index in the list, negates the typical purpose of an immutable identifier, and enforces a common anti-pattern that monotonically numbered items need to be/stay gap free, in this case causing more busy work.
  • 0 Votes
    2 Posts
    127 Views
    J
    @jdent I am pretty sure this is it!!
  • QSqlQuery does not return a record set?

    Solved qsqlquery results
    7
    0 Votes
    7 Posts
    717 Views
    J
    @Christian-Ehrlicher Thanks!!
  • how to use "cascaded connect "?

    Moved Unsolved
    7
    0 Votes
    7 Posts
    547 Views
    Pl45m4P
    @AnneRanch said in how to use "cascaded connect "?: How do I code the "child class" to use the "parent class " "connect"? After reading this again... is it about INHERITING signals/slots from "parent" or a base class? Your "parent" as you call it, has a signal ping() and is connected to a slot in widget B... and now you want to have the same connection to B in a child QObject of A? That's not possible. Parent/Child are two different QObjects and you have to connect each independently. You can inherit signals from a base class, but class inheritance is not the same thing as a QObject Parent-child relation....
  • QString Turkish Character Problem

    Unsolved
    4
    0 Votes
    4 Posts
    825 Views
    Christian EhrlicherC
    @JonB said in QString Turkish Character Problem: how ridiculously complicated language encoding is in C++! It's more a windows/msvc problem using anything else but utf-8 for the source files and even during runtime.
  • Tab order does not work in Qt

    Moved Unsolved
    2
    0 Votes
    2 Posts
    461 Views
    Christian EhrlicherC
    Please provide a minimal, compilable example of your problem. No designer stuff needed to reproduce this issue.
  • Why the icon is so blurry,so much little mosaic

    Unsolved
    13
    0 Votes
    13 Posts
    1k Views
    Christian EhrlicherC
    You should update to 6.7 to get proper High-DPI support. Qt5 had a lot of issues with that.
  • Qt executables missing in 6.6.3\msvc2019_arm64\bin folder

    Unsolved
    3
    0 Votes
    3 Posts
    262 Views
    N
    @SGaist Bug report created: https://bugreports.qt.io/browse/QTBUG-123870
  • Error when building MQTT for Android

    Solved
    6
    0 Votes
    6 Posts
    492 Views
    R
    @aiya12 我解决了,有空写个教程,现在忙于找工作中…… I solved it. I will write a tutorial when I have free time. I'm busy finding a job now……
  • Problem with openssl

    Unsolved
    2
    0 Votes
    2 Posts
    244 Views
    C
    @YassineJ said in Problem with openssl: i have installed openssl, Which version? I think you need OpenSSL 1.0.x version for this Qt version. OpenSSL 1.1.x you need Qt 5.12+ added it to path, added the dll files (ssleay32.dll and libeay.dll) If it is in the system PATH then the DLLs should be found without copying them. to the project folder The should be in the same location as the executable if they are not on the PATH. This is typically not the same as the source folder if you are using any sort of disciplined IDE.
  • This topic is deleted!

    Unsolved
    2
    0 Votes
    2 Posts
    2 Views
  • 500 Variables in class how to get/set/store in json efficiently?

    Unsolved c++ qt variable template struct json
    30
    0 Votes
    30 Posts
    5k Views
    S
    @SGaist I actually have some of them built already. Thats why i was asking what would be better/ if my approach with the database would be viable. :) Have a nice easter.
  • qglobal.h:391:11: error: 'maybe_unused' attribute cannot be applied to types

    Unsolved
    4
    0 Votes
    4 Posts
    1k Views
    E
    @rgov Have you found a solution to this problem? I am encountering the same issue.
  • stop capture keyboard event

    Unsolved
    2
    0 Votes
    2 Posts
    164 Views
    SGaistS
    Hi and welcome to devnet, releaseKeyboard is the complementary function of grabKeyboard.