Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.5k Topics 457.3k Posts
  • Signal is not read by the Class

    Solved
    22
    0 Votes
    22 Posts
    2k Views
    V
    @jsulm https://forum.qt.io/post/775285
  • Build worked with QT6.2.4 but failing with QT6.5.3

    Unsolved
    4
    0 Votes
    4 Posts
    381 Views
    S
    Created bug report: https://bugreports.qt.io/browse/QTBUG-118406
  • QString::number(14.24,'g',3) returns 14.3 ?

    Unsolved
    3
    0 Votes
    3 Posts
    2k Views
    Paul ColbyP
    I used QString::number(doubleNumber, 'g' , 3) to get String representing the significant decimals up to 3. The g format doesn't give 3 "significant decimals", it gives 3 "significant digits" - this includes digits both before (excluding leading 0's) and after the decimal. Have a read of https://en.wikipedia.org/wiki/Significant_figures for more info. It works well in 99.9999% cases but for 14.25 instead of giving 14.25 it returns 14.3 14.3 is correct. The three significant digits there are 1, 4, and .3. I know I could use QString::number(doubleNumber'f',3) ... Why is that The reason the f format gives more decimals in your example, is that the f format interprets the precision parameter as a number of decimals, whereas g interprets it as a number of significant digits (which, as I mentioned above, includes digits before the decimal too). This is documented in the table under QLocale::toString(), which QString::number() links to (and @JonB referenced above). See the "Meaining of precision column: [image: 2f1ad327-50d1-40ae-a2f0-d5cf4ca0c35c.png] and what to use instead? If you specifically want "up to 3 decimals", as opposed to "exactly 3 decimals" (f) or "up to 3 significant digits" (g), then I suppose using f then trimming trailing 0 chars is one way to go. Just one of many ways to do it: const double doubleNumber = 14.25; qDebug() << QString::number(doubleNumber,'f',3); qDebug() << QString::number(doubleNumber,'g',3); qDebug() << QString::number(doubleNumber,'f',3).remove(QRegularExpression(QStringLiteral("0+$"))); Outputs: "14.250" "14.3" "14.25" Cheers.
  • Default layout alignment

    Unsolved
    2
    0 Votes
    2 Posts
    234 Views
    C
    @1XU7 Different in what way? You are setting the layout's alignment within its parent. The widgets you put in the layout have their own alignment value.
  • Qt6 Replacement for QMediaPlayer::hasSupport()

    Unsolved qmediaplayer qt5.15.0 qt6.5.0
    3
    0 Votes
    3 Posts
    687 Views
    SGaistS
    Hi, To add to @KH-219Design, since 6.5, the default backend has been set to ffmpeg.
  • QTreeView Remove and Re-Insert childitem from parent?

    Unsolved
    18
    0 Votes
    18 Posts
    1k Views
    S
    @Christian-Ehrlicher So i got this working pretty great, but somehow when i move 2 items at ones out of it's parent only the data of one item gets copied over to both new inserted items: This i the start situation (1 parent with 2 child items): [image: 7af7df79-973a-4e1d-ae2a-a21aebd2be91.png] Than i select both items and drop than onto their parent item: [image: 0b7bbbd0-3700-4b67-9d56-b3ea8d06d023.png] After dropping i get two items named identically, but instead they should keep their data: [image: 8fe0b267-976b-43d6-81e0-7d0c679fa1ad.png] Here is my code: void ViewLayerList::dragEnterEvent(QDragEnterEvent *event) { // Ermitteln Sie den Index des Items unter der Maus QModelIndex index = indexAt(event->position().toPoint()); if (!index.isValid()) { // Wenn kein gültiges Item unter der Maus ist, rufen Sie die Basisklasse-Methode auf und kehren Sie zurück QTreeView::dragEnterEvent(event); return; } // Zugriff auf das Modell QStandardItemModel *modelObj = dynamic_cast<QStandardItemModel*>(model); // Überprüfen Sie, ob das Modell korrekt gecastet wurde if (modelObj) { // Vor jedem Drag-Event leeren Sie die Parent-Index-Liste parentChildMap.clear(); selectedIndexList.clear(); // Sammeln Sie die Parent-Indizes für ausgewählte Items QModelIndexList selectedIndexes = selectionModel()->selectedIndexes(); for (const QModelIndex& selectedIndex : selectedIndexes) { QModelIndex parentIndex = selectedIndex.parent(); // Fügen Sie das Paar zur Map hinzu parentChildMap.insert(selectedIndex, parentIndex); // Fügen Sie den ausgewählten Index zur Liste hinzu selectedIndexList.append(selectedIndex); // Zugriff auf das ausgewählte Element und fügen Sie es zur Liste hinzu QStandardItem* selectedItem = modelObj->itemFromIndex(selectedIndex); } int selectedItemCount = selectedIndexes.count(); qDebug() << "Anzahl der ausgewählten Items: " << selectedItemCount; // Nachdem Sie die Map gefüllt haben... for(auto it = parentChildMap.constBegin(); it != parentChildMap.constEnd(); ++it) { qDebug() << "Child: " << it.key().data() << ", Parent: " << it.value().data(); } } QTreeView::dragEnterEvent(event); } void ViewLayerList::dropEvent(QDropEvent *event) { // Ermitteln Sie den Index des Items unter der Maus QModelIndex index = indexAt(event->position().toPoint()); if (!index.isValid()) { QTreeView::dropEvent(event); return; } QModelIndex destinationIndex = indexAt(event->position().toPoint()); // Rufen Sie die Basisklasse-Methode auf, um die Standard-Verarbeitung fortzusetzen QTreeView::dropEvent(event); // Zugriff auf das Modell QStandardItemModel *modelObj = dynamic_cast<QStandardItemModel*>(this->model); // Überprüfen Sie, ob das Modell korrekt gecastet wurde if(modelObj) { qDebug() << "destinationIndex data: " << destinationIndex.data(); // Überprüfen Sie, ob der Zielindex das Wurzelelement als Elternteil hat bool isDestinationRoot = (destinationIndex.parent() == QModelIndex()); qDebug() << "DestinationHasROOT as parent: " << isDestinationRoot; // Nachdem Sie das Ereignis verarbeitet haben... for (const QModelIndex& selectedIndex : selectedIndexList) { // Holen Sie sich den Elternindex für das ausgewählte Element QModelIndex parentIndex = parentChildMap.value(selectedIndex); // Zugriff auf das Elternelement QStandardItem* parentItem = modelObj->itemFromIndex(parentIndex); // Vergleichen Sie die Daten des Elternindex mit den Daten des Zielindex if(parentIndex.data() == destinationIndex.data() && isDestinationRoot) { // Entfernen Sie das Kind-Element aus seinem Elternelement int row = 0; QList<QStandardItem*> items = parentItem->takeRow(row); //THIS COMMET BEHAVES REALLY STRANGE WHEN I REMOVE IT //SEE THE PICTURE BELOW qDebug() << "ItemList:" << parentItem->takeRow(row); // Bestimmen Sie die Position, an die das Element verschoben werden soll int newPosition = parentIndex.row() + 1; // Fügen Sie das Kind-Element an der neuen Position zum invisibleRootItem hinzu modelObj->invisibleRootItem()->insertRow(newPosition, items); } } } } There also is this one comment, everytime i try to remove it,my items get only copied in the dragging process but not removed anymore, so i end up with copies like this: (if the comment is there everything works fine, i found that strange) [image: bb1f24a2-433c-49f4-974b-9a6a90c802a1.png] I only commented out the comment: //qDebug() << "ItemList:" << parentItem->takeRow(row);
  • Memory leak in libQt5Core.so.5.15.7

    Unsolved
    5
    0 Votes
    5 Posts
    447 Views
    jsulmJ
    @chandrakant2023 https://lists.qt-project.org/listinfo/development
  • AUDIOSES.DLL errors on MinGW, but not on MSVC

    Unsolved
    1
    0 Votes
    1 Posts
    470 Views
    No one has replied
  • 0 Votes
    1 Posts
    183 Views
    No one has replied
  • Mouse position issue

    Solved
    3
    0 Votes
    3 Posts
    326 Views
    PerdrixP
    @sierdzio I changed the if statement to read: if (!underMouse() || !displayRect.contains(mouseLocation)) return; and added an update() call to the leaveEvent() handler. Problem solved.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • Qt 6.6 Captures images or Video to file crash the application

    Unsolved
    2
    0 Votes
    2 Posts
    185 Views
    jsulmJ
    @Ahimson2 First thing to do if your app is crashing: run through debugger and see where exactly it crashes. You can also post stack trace after crash here. Else we cannot do more than guessing.
  • how to zip and unzip in QT

    Unsolved
    3
    0 Votes
    3 Posts
    2k Views
    jsulmJ
    @jgxy1123 See https://forum.qt.io/topic/74306/how-to-manage-zip-file
  • Sqlite Multithread

    Unsolved
    6
    0 Votes
    6 Posts
    897 Views
    piervalliP
    @KenAppleby-0 In the documentations of Qt https://doc.qt.io/qt-5/sql-driver.html#qsqlite SQLite has some restrictions regarding multiple users and multiple transactions. If you try to read/write on a resource from different transactions, your application might freeze until one transaction commits or rolls back. The Qt SQLite driver will retry to write to a locked resource until it runs into a timeout (see QSQLITE_BUSY_TIMEOUT at QSqlDatabase::setConnectOptions()). In the Sqlite documentation https://www.sqlite.org/c3ref/c_config_covering_index_scan.html#sqliteconfigserialized SQLITE_CONFIG_SERIALIZED There are no arguments to this option. This option sets the threading mode to Serialized. In other words, this option enables all mutexes including the recursive mutexes on database connection and prepared statement objects. In this mode (which is the default when SQLite is compiled with SQLITE_THREADSAFE=1) Final considerations Sqlite is builded with flag THREADSAFE=1 we can check with the query "PRAGMA compile_options;", all mutex are enabled and for default configuration thread mode is SQLITE_CONFIG_SERIALIZED. Until the timeout Sqlite retry to write. For my case I changed to timeout to 5 minute i haved limited the transaction to strictly necessary, because the transaction locks all. In addition PRAGMA journal_mode=WAL; is useful for multithreading. The global QMutex is not necessary.
  • In MAC Send/Write audio data on partcular output channel of audio device

    Unsolved
    7
    0 Votes
    7 Posts
    576 Views
    SGaistS
    I think you have a use case that shows the limit of the current implementation. You should open a bug report to explain your situation and issue.
  • Trying to set the colour for hyperlinks in QTextBrowser

    Unsolved
    12
    0 Votes
    12 Posts
    2k Views
    Gojir4G
    @Perdrix Sorry to come later on this. But there is an interesting note about this in documentation of QPalette: Note that we do not use the Link and LinkVisited roles when rendering rich text in Qt, and that we recommend that you use CSS and the QTextDocument::setDefaultStyleSheet() function to alter the appearance of links. For example: QTextBrowser browser; QColor linkColor(Qt::red); QString sheet = QString::fromLatin1("a { text-decoration: underline; color: %1 }").arg(linkColor.name()); browser.document()->setDefaultStyleSheet(sheet);
  • Qt and coroutines

    Unsolved
    13
    0 Votes
    13 Posts
    2k Views
    F
    Thank you for all your support guys! Everything is much more clear now!
  • QListWidget, new selections, last selections

    Solved
    3
    0 Votes
    3 Posts
    187 Views
    SPlattenS
    @jsulm , thank you, thats what I'm looking at implementing now.
  • QTextStream question

    Solved
    16
    0 Votes
    16 Posts
    2k Views
    Q
    @JoeCFD said in QTextStream question: std::cout << qPrintable( QString( "%1." ).arg( a, 2, 10, QChar( '0' ) ) ) << qPrintable( QString( "%1" ).arg( b, 2, 10, QChar( '0' ) ) ) << std::endl; Compare your statement with mine if I define a simple macro: #define co(width, what) qSetPadChar('0') << qSetFieldWidth(width) << what << qSetFieldWidth(0) Then: "01.02" output is much simpler: cout << co(2,a) << co(0,'.') <<co(2, b) << Qt::endl;
  • windeployqt: Unable to locate ICU library icudt72.dll

    Unsolved
    1
    0 Votes
    1 Posts
    329 Views
    No one has replied