Skip to content
  • 0 Votes
    8 Posts
    4k Views
    mrjjM

    @spektro37
    Well its used with all QWidgets so would make sense.

    Its something to be aware of when creating GUI and also the little note that
    any QWidget that are not given a owner/parent, will become a window.
    That can be surprised when coming from other frameworks.

    Say you make a new label

    QLabel *lab= new QLabel();

    Since its given no parent, it will become a window.

    That was pretty surprising to me first time as i wanted to insert it into the main window.

    So its good to know about.

  • 0 Votes
    8 Posts
    3k Views
    VRoninV

    @SergeyK12 said in Unite data from two QSqlRelationTableModel into one TableView:

    I reimplement the following method of QIdentityProxyModel:

    data, index, columnCount
    add a private field with QSqlRelationTableModeland the setter.

    I suppose there is something alse which i should reimplement to make field in 5 cell editebel. SetData ofcource, but why is it in a gray mode? There is a method which make cells editable?

    You can't have a proxy model with 2 source models. internally it will rely on mapFromSource and mapToSource which won't work in your case, start directly from QAbstractItemModel.

    The methods you reimplemented are fine, you miss rowCount(), setData() and flags()

    use KDE (but its too hard to build a library).

    no it's not... detailed instructions to build any tier 1 KDE module (spoiler alert: it's only 9 cmd lines): https://forum.qt.io/topic/76533/copy-selected-rows-of-a-table-to-a-model/12

  • 0 Votes
    17 Posts
    11k Views
    jwernernyJ

    I've uncovered the same issue with QSqlQueryModel using the Windows QODBC database engine connected to MS SQL Server, and have been do some digging. Hopefully this will help others experiencing this issue.

    There are a couple of different things happening here.

    First, QSqlQueryModel does not support forward only queries. If you try to use a forward only query, QSqlQueryModel::lastError() will return "Forward-only queries cannot be used in a data model".

    That seems clear, but does not explain the situation when the forward only is left in its default false state or explicitly set in code. During my exploration of the issue, I would notice that even though I called QSqlQuery::setForwardOnly(false), a call to QSqlQuery::isForwardOnly() made after the query was executed would show forward only set to true, something I did not understand.

    Then I read the Qt documentation for setForwardOnly:

    Setting forward only to false is a suggestion to the database engine, which has the final say on whether a result set is forward only or scrollable. isForwardOnly() will always return the correct status of the result set.

    The database engine has the final say whether or not forward only is used!

    Why was the database engine setting forward only? Qt's SQL Database Drivers documentation gives part of the answer if you know what you are looking at.

    ODBC Stored Procedure Support

    With Microsoft SQL Server the result set returned by a stored procedure that uses the return statement, or returns multiple result sets, will be accessible only if you set the query's forward only mode to forward using QSqlQuery::setForwardOnly().

    By observation, the QODBC database engine (in Qt 5.8) recognizes when more than one return set has resulted from the query, so it is automatically setting forward only to true.

    How are multiple result sets generated? I've uncovered a few ways.

    A query that has multiple select statements (e.g. select * from table1; select * from table2). Stored Procedures In particular, MS SQL Server documentation has this to say:

    SQL Server stored procedures have four mechanisms used to return data:

    Each SELECT statement in the procedure generates a result set. The procedure can return data through output parameters. A cursor output parameter can pass back a Transact-SQL server cursor. The procedure can have an integer return code.

    The first item in Microsoft's list was the key for me. When NOCOUNT is OFF, Even a simple internal variable assignment using a select (e.g. select @user = 'fred') generated a return set. Setting NOCOUNT to ON stops this behavior. From Microsoft's documentation on NOCOUNT

    SET NOCOUNT ON prevents the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. For stored procedures that contain several statements that do not return much actual data, or for procedures that contain Transact-SQL loops, setting SET NOCOUNT to ON can provide a significant performance boost, because network traffic is greatly reduced.

    The Solution for me turned out to be two things:

    Add SET NOCOUNT ON to the top of my stored procedure so that only the select statement I cared about was returned Instead of using QSqlQueryModel, manually extract the results from the query and build my own QStandardItemModel.
  • 0 Votes
    4 Posts
    2k Views
    mrjjM

    @michalos
    Well knowing windows searching, i always cheat and use
    https://www.voidtools.com/
    On NTFS drives, it will find anything really fast and takes wildcards.
    Its only for filenames but on the other hand, it finds a file in secs even on a 4 TB drive. :)

  • 0 Votes
    11 Posts
    14k Views
    michalosM

    Thanks :)

  • 0 Votes
    1 Posts
    2k Views
    No one has replied
  • 0 Votes
    17 Posts
    7k Views
    mrjjM

    @SGaist
    is VS express not excotic enough ? ;)

  • 0 Votes
    8 Posts
    4k Views
    SGaistS

    Can you show how you setup and run your query ?

  • 0 Votes
    6 Posts
    7k Views
    kshegunovK

    @Kofr
    If the above snippet works, then you don't respect the SQL's type. You're trying to pass a string representation to Qt when it clearly expects a binary (BLOB is "Binary Large OBject"). So then the question:

    How to fix Qt implementation?

    comes back as: "How to fix your implementation".
    Anyway, I'd suggest passing the appropriate type to the driver. My thoughts are that something like this should be working:

    const char rawData[4] = { 0x00, 0x00, 0x00, 0x07 }; QByteArray id = QByteArray::fromRawData(rawData, 4); QSqlQuery query; if (!query.prepare(QStringLiteral("SELECT row FROM %1 WHERE id = :id").arg(tableName))) // Handle the error! query.bindValue(":id", id); // Pass binary data for columns that expect binary if (!query.exec()) // Handle error again!
  • 0 Votes
    16 Posts
    7k Views
    ?

    Hi! Just to be sure I understood this correctly: You have a single DB with a humongous number of identically structured tables? Do you really believe you can store 2^128 bits / rows / tables / whatever in your database / filesystem / datacenter?

    In worst case I will have to keep in RAM about 4e+38 of 16 bytes pointers

    Even that is way more rows than what a SQLite table can hold (see: https://www.sqlite.org/limits.html).

  • SQL query not working

    Unsolved General and Desktop
    10
    0 Votes
    10 Posts
    5k Views
    T

    Hi!

    You should get the error-message as already mentioned above:

    QSqlQuery a; if( !a.exec("Select Stock From Manufacturer_stock Where Product='Parle';") ) { qDebug() << "Error:" << a.lastError().text(); }
  • 0 Votes
    6 Posts
    4k Views
    p3c0P

    @Cleiton-Bueno Yes. If the query string is correct it will work.

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    You understood it correctly.

    Note that since 5.7 you can use qOverload which makes the code easier to read.

  • 0 Votes
    16 Posts
    7k Views
    A

    can i export this script to windows and use it there?

  • 0 Votes
    2 Posts
    1k Views
    SGaistS

    Hi,

    At first sight your position parameter to bindValue are wrong. You have two values so it should be 0 and 1 not 1 and 2.

  • 0 Votes
    4 Posts
    2k Views
    D

    Thanks everyone

  • 0 Votes
    6 Posts
    3k Views
    SGaistS

    That might happen ;)

    By the way, no need to modify the title anymore. You can use the topic tool button to mark the thread as solved :)

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    Well, follow the documentation starting here. You'll find the relevant topics on how to connect to a database, run queries, use models etc.