Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.5k Topics 457.3k Posts
  • QSqlRelationalTableModel with QDataWidgetMapper does not save to SQLite3 database

    Solved
    10
    0 Votes
    10 Posts
    592 Views
    ?
    Everything works now as expected. You can find the solution here
  • Subclass QItemDelegate not working

    Solved
    5
    0 Votes
    5 Posts
    392 Views
    ?
    I have found the error. The error was in the database. Here "not null" was set. The following code now works as expected: void NullDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { const QByteArray name = editor->metaObject()->userProperty().name(); if(!name.isEmpty()){ if(editor->property(name).toString().isEmpty()){ model->setData(index, QVariant(), Qt::EditRole); } else { model->setData(index, editor->property(name), Qt::EditRole); } } void NullDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QVariant data = index.data(Qt::EditRole); const QByteArray name = editor->metaObject()->userProperty().name(); if (!name.isEmpty()) { if (!data.isValid()) data = QVariant(editor->property(name).userType(), (const void *)0); editor->setProperty(name, data); } }
  • QGraphicsView white flicker on refresh

    Solved
    2
    0 Votes
    2 Posts
    512 Views
    C
    I have managed to fix problem. The issue was that the other thread that was populating the QImage was not synchronized with the render thread and it was trying to render half populated images and stuff like that. I have added a simple check to know when QImage was completely populated and only then render the image and the flickering is completely gone.
  • Why Qbytearray.mid() method remove charactor "0D" from new QBytearray

    Solved
    4
    0 Votes
    4 Posts
    520 Views
    stackprogramerS
    @ChrisW67 exactly my problem was QIODevice::Text ... thanks
  • overlapping of widgets in Qt

    Unsolved
    2
    0 Votes
    2 Posts
    199 Views
    Christian EhrlicherC
    You can set the background color/image of a widget but widgets can not 'overlap'. See e.g. https://forum.qt.io/topic/1378/is-it-possible-to-set-a-background-image-to-a-widget
  • Making a QScrollArea take only the space it's contents need

    Unsolved
    2
    0 Votes
    2 Posts
    243 Views
    D
    I fiddled with QScrollArea too recently. My advice: try to solve column layout without QScrollArea. Check QWidget::minimumSizeHint. When your column layout works without QScrollArea, then adding QScrollArea with setWidgetResizable(true) should do the job. At least it worked for me.
  • Extra line in radio group

    Solved
    7
    0 Votes
    7 Posts
    689 Views
    jronaldJ
    @Christian-Ehrlicher said in Extra line in radio group: Ok, I don't have this font. Maybe you should open a bug report with a minimal example. Reported, https://bugreports.qt.io/browse/QTBUG-98322 Thanks
  • Concurrent database access coding

    Unsolved
    3
    0 Votes
    3 Posts
    350 Views
    SGaistS
    Hi, Beside @JonB excellent advices, concurrent shared access of SQLite files on network drives is highly discouraged. See the official SQLite documentation chapter on this matter.
  • Inexplicable QSqlQueryModel handling of NULL value

    Solved
    14
    0 Votes
    14 Posts
    5k Views
    D
    @JonB said in Inexplicable QSqlQueryModel handling of NULL value: The PyQt author tells me this is "a very unusual case" and he thinks it "may be the only one" which exists where this is a problem. I worry about others, but have to take his word for now. I am a little bit astonished, that he said that. There are various situations where you have to distinguish between NULL and a ""/0 value, especially in case of ints. you want to generate INSERT statements for an import into another database you want to export a CSV file with a correct representation of database rows I thought it was obvious that NULL and ''/0 are very much different (though Oracle treats empty strings as NULL, but never the other way around) and that a NULL value must never be converted to anything "NOT NULL", if not explicitly requested. But I found a workaround by using query.record().isNull(i) that works for me: query = QSqlQuery(self.db) query.exec('SELECT NULL') # add "FROM DUAL" for databases which need it if query.isActive(): if query.isSelect(): while query.next(): # QSqlRecord::isNull(int index) will behave correctly print(query.record().isNull(0)) # QSqlQuery::value(int index) will return the (incorrectly) converted value print(query.value(0)) # is converted to int(0) or str('') ```
  • Qt Bluetooth keeps on "Connecting state"

    Unsolved bluetooth arduino ubuntu
    6
    0 Votes
    6 Posts
    1k Views
    M
    @mrjj Hi Again, I just noticed that despite not being able to pair, I can connect to the bluetooth module using connect (in bluetoothctl). Could it be that Qt internally always tries to pair before connect, and that's why it cannot connect?
  • This topic is deleted!

    Moved Unsolved
    3
    0 Votes
    3 Posts
    50 Views
  • How do you handle selection of QGraphicsItem?

    Unsolved
    15
    0 Votes
    15 Posts
    1k Views
    D
    @Pl45m4, at that time I didn't have the call setSceneRect(....). With that line, now it doesn't move.
  • How to get this style on a button

    Unsolved qstyle qstylesheet fusion
    10
    0 Votes
    10 Posts
    3k Views
    L
    @Dariusz said in How to get this style on a button: @JKSH AH yes, could do... but I'm trying to css entire app with hundreds of buttons/etc.. I think you could inherit from the QPushButton then: class MyButton : public QPushButton { MyButton( ... ) : ... { setMinimumSize( ... ); } };
  • QT 6.3 cmake adding icons OSX

    Solved
    4
    0 Votes
    4 Posts
    531 Views
    Z
    Hi everyone, CMake help files can be a bit obscure - however, I sorted it out. I think a bit more in integrating cmake with QT Creator would help. Anyway, for anyone else trying to add icns to QT with OSX, you need to add these lines before "find package" (substitute your icns file and names as appropriate): set(MACOSX_BUNDLE_ICON_FILE Stubtiler.icns) set(Stubtiler_ICON "${CMAKE_CURRENT_SOURCE_DIR}/Stubtiler.icns") set_source_files_properties(${Stubtiler_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") Then in: if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(StubTiler MANUAL_FINALIZATION StubResources.qrc # add resources files ${Stubtiler_ICON} # add icns here ${PROJECT_SOURCES} ) Hope this helps anyone else facing the same problem Ziggx
  • How to get file and dir list from server

    Solved
    2
    0 Votes
    2 Posts
    189 Views
    JonBJ
    @tovax Yes you will want FTP. Problem is that QFtp got discontinued. Follow the advice/links of the replies in that thread: @VRonin : You can either recompile the old QFtp Module or use an external library like libcurl @joeQ : I think, the Github Qt Ftp, Can help. Use It maybe easy.
  • How to eject USB flash disk?

    Solved
    6
    0 Votes
    6 Posts
    2k Views
    tovaxT
    @jsulm @Pl45m4 I have been using the "usb-ejecter.exe" downloaded from the Internet before, and recently I found the code to eject the USB flash drive on win10, and it is currently running well. bool usbDriveEject(const QString letter) { QString device_path = QStringLiteral("%1:\\").arg(letter); QString error_string; const char* temp = "\\\\.\\"; char device_path1[10] = { 0 }; memcpy(device_path1, temp, strlen(temp)); QByteArray dp = device_path.toLocal8Bit(); device_path1[4] = dp.at(0); device_path1[5] = dp.at(1); HANDLE handleDevice = CreateFileA(device_path1, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); bool is_handle_invalid = (handleDevice == INVALID_HANDLE_VALUE); if (is_handle_invalid) { error_string = "Device is not connection to system!"; qDebug() << GetLastError(); return false; } // Do this in a loop until a timeout period has expired const int try_lock_volume_count = 3; int try_count = 0; for (; try_count < try_lock_volume_count; ++try_count) { DWORD dwBytesReturned; if (!DeviceIoControl(handleDevice, FSCTL_LOCK_VOLUME, nullptr, 0, nullptr, 0, &dwBytesReturned, nullptr)) { qDebug() << "Device is using....." << try_count; break; } QThread::sleep(1); } if (try_count == try_lock_volume_count) { error_string = "Device is using, try again later"; CloseHandle(handleDevice); return false; } DWORD dwBytesReturned = 0; PREVENT_MEDIA_REMOVAL PMRBuffer; PMRBuffer.PreventMediaRemoval = FALSE; if (!DeviceIoControl(handleDevice, IOCTL_STORAGE_MEDIA_REMOVAL, &PMRBuffer, sizeof(PREVENT_MEDIA_REMOVAL), nullptr, 0, &dwBytesReturned, nullptr)) { error_string = QStringLiteral("Unmount failed! error code:%1").arg(GetLastError()); qDebug() << "DeviceIoControl IOCTL_STORAGE_MEDIA_REMOVAL failed:" << GetLastError(); CloseHandle(handleDevice); return false; } long bResult = 0; DWORD retu = 0; bResult = DeviceIoControl(handleDevice, IOCTL_STORAGE_EJECT_MEDIA, nullptr, 0, nullptr, 0, &retu, nullptr); if (!bResult) { error_string = QStringLiteral("Disconnect IGU failed! error code:%1").arg(GetLastError()); CloseHandle(handleDevice); qDebug() << "Disconnect IGU IoControl failed error:" << GetLastError(); return false; } CloseHandle(handleDevice); return true; }
  • How to upgrade the program by itself

    Unsolved
    5
    0 Votes
    5 Posts
    480 Views
    tovaxT
    @JonB Hi, thanks very much! In order to allow users to flexibly choose the version they want to upgrade, I decided to make a separate updater.exe. I'm debugging this gadget, and I will give you a reply when it's finished.
  • How to stop click propagation in QGraphicsScene without making ItemIsSelectable?

    Unsolved
    3
    0 Votes
    3 Posts
    277 Views
    D
    @JonB, It's hard to control the selection mechanism of scene. Depending on where one clicks, scene automatically selects/deselects item. So instead of using the setSelected/isSelected in Slice, I've creted isChecked/setChecked to control the movements of Slice and removed ItemIsSelectable flag from Slice constructor. In PieView made these changes: scene->setSceneRect(0,0,200,200); ellipse = new QGraphicsEllipseItem(); ellipse->setBrush(Qt::white); ellipse->setPen(Qt::NoPen); ellipse->setAcceptHoverEvents(true); ellipse->setFlag(QGraphicsItem::ItemIsSelectable); text = new QGraphicsTextItem(ellipse); text->setAcceptHoverEvents(false); the weird movement of slices, when mouse first entered, was solved by setting setSceneRect. With these changes, drawings and slice movements are almost perfect. A rectangular dashed border becomes visible when I click on the ellipse: [image: e3fee02c-9abe-4262-b053-9bd87c498000.gif] That's weird! In some places I've seen people suggested to subclass the ellipse and override the paint BUT that's a lot for such a simple thing. Is there any other way to remove that border around the ellipse?
  • A strange IP Address in QUdpSocket

    Solved
    2
    1 Votes
    2 Posts
    502 Views
    C
    @qwe3 said in A strange IP Address in QUdpSocket: But what is ::ffff:192.168.0.30? This is a strange string which is concatenation IPv4 address ( 192.168.0.30 ) and IPv6 address ( ::ffff: ). That is the RFC5952 format for a special IPv6 address where the IPv4 address is the last four octets. These addresses are usually associated with tunneling IPv4 inside IPv6. For readability these four octets can be displayed in decimal as is convention in IPv4. And why sender send datagram using IPv6? In writeDatagram I wrote "192.168.0.45" and this is IPv4 Address You have asked the operating system to deliver a datagram to an IPv4 address. That does not obligate the OS, or the network in between, to use an IPv4 interface to achieve that. It seems your environment has a preference. On the receiving end, you have have called bind() in a way that should respond to a datagram on any IPv4 or IPv6 interface (QHostAddress::Any). What happens if you bind() to QHostAddress::AnyIPv4?
  • Who closes application on Escape?

    Solved
    13
    0 Votes
    13 Posts
    2k Views
    D
    Hi, thanks to your numerous "Qt won't do that" it was easy to me to find the culprit. @JonB said in Who closes application on Escape?: I can only think that somehow this is relevant. You're right. I use an opencascade widget, which I didn't spend much time for investigation. I just used it as is. And that widget killed the app at Escape key press. Anyway - with this lesson I learned a lot about event-handling in Qt.