Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.4k Topics 456.4k Posts
  • Verify internet connection from QThread

    Unsolved
    4
    0 Votes
    4 Posts
    242 Views
    J
    @Jalkhov said in Verify internet connection from QThread: Ok, I have adapted the code, it would look like this? from PyQt5.QtWidgets import QWidget, QPushButton, QApplication, QListWidget, QGridLayout, QLabel from PyQt5.QtCore import QTimer, QDateTime, QThread, pyqtSignal import requests import sys class CheckThread(QThread): statusChanged = pyqtSignal(bool) def run(self): try: request = requests.get("http://www.google.com", timeout=5) self.statusChanged.emit(True) except (requests.ConnectionError, requests.Timeout) as exception: self.statusChanged.emit(False) class WinForm(QWidget): def __init__(self, parent=None): super(WinForm, self).__init__(parent) self.setWindowTitle('QTimer example') self.listFile = QListWidget() self.label = QLabel('Label') self.startBtn = QPushButton('Start') self.endBtn = QPushButton('Stop') self.count = 0 layout = QGridLayout() self.timer = QTimer() self.timer.timeout.connect(self.showTime) layout.addWidget(self.label, 0, 0, 1, 2) layout.addWidget(self.startBtn, 1, 0) layout.addWidget(self.endBtn, 1, 1) # self.startBtn.clicked.connect(self.startTimer) self.endBtn.clicked.connect(self.endTimer) self.setLayout(layout) self.check_thread = CheckThread() self.check_thread.statusChanged.connect(self.handle_status_changed) self.startBtn.clicked.connect(self.start_thread) def start_thread(self): self.start = True self.timer.start(100) self.startBtn.setEnabled(False) self.endBtn.setEnabled(True) def handle_status_changed(self, status): print(status) def showTime(self): self.count += 1 time = self.count / 10 self.label.setText(str(time)) if time % 5 == 0: self.check_thread.start() def endTimer(self): self.count = 0 self.timer.stop() self.startBtn.setEnabled(True) self.endBtn.setEnabled(False) self.label.setText("0") if __name__ == '__main__': app = QApplication(sys.argv) form = WinForm() form.show() sys.exit(app.exec_()) I placed self.check_thread.start() inside the showtime function because that way it is shown at the time interval indicated by the if, I don't know if it is right like that.
  • [Solved] QDockWidget - disable "always on top"

    14
    0 Votes
    14 Posts
    10k Views
    B
    @Chris-Kawa said in [Solved] QDockWidget - disable "always on top": As such they don't show up in the taskbar as separate windows. If such window would become hidden under its parent there would be no way for user to know it's there or switch to it. Is this possible to do in PySie2 or 6.0.1? I mind undock QDockWidget and manage this from windows taskbar like sepaarate aps/windows?
  • Bug when attempting embedding widget in container with thread

    Unsolved
    3
    0 Votes
    3 Posts
    227 Views
    W
    @Christian-Ehrlicher Understood. Thanks for your reply
  • 0 Votes
    18 Posts
    809 Views
    SGaistS
    Exactly like you were already explained: do that after the exec call.
  • Using qtconncetivity btscanner update - FYI only

    Unsolved
    1
    0 Votes
    1 Posts
    157 Views
    No one has replied
  • Keyboard inputs when a Qdialog opened.

    Solved
    11
    1 Votes
    11 Posts
    831 Views
    mrjjM
    @Alex_Spi13 Hi Ahh. yes SDL is completely the opposite in regards to input as there one has to read it in a loop as you say. Nice day to you too :) Please flag as solved using the Topic button in first post.
  • Understanding warning "Returning data of temporary object"

    Solved
    4
    0 Votes
    4 Posts
    1k Views
    mrjjM
    @saa_ Hi Well it kinda depends on what we want to return. Sometimes we can get away with simply returning a copy. Like QString SomeFunc() then the Qstring does the copying for us. if we are talking a char * from a container like qbytearry the best way would be to allocated storage for it as docs shows. QString tmp = "test"; QByteArray text = tmp.toLocal8Bit(); char *data = new char[text.size() + 1]; strcpy(data, text.data()); and use that buffer. but that also places the burden on the caller to remember to deallocate the buffer. So when this i needed to do then using a smart pointer to hangle the char * buffer can be used. However, its not 100% the whole truth https://en.cppreference.com/w/cpp/language/lifetime (Temporary object lifetime) So you might get away with code belov as when part of the calling expressions, the compiler might keep it alive. char* qStringToCharPtr(QString string) { return string.toLocal8Bit().data(); }
  • Segmentation fault

    Solved
    11
    0 Votes
    11 Posts
    723 Views
    TequiloutreT
    OW FFS I hate myself. @jeremy_k were right. I'm a beginner with Qt and I've made a stupid mistake. I told myself "Hey you're creating pokemon_1 as a new pointer so you dynamicaly allocate some memory that have to be freeded at the end of the program haha" I had those lines at the end of my main_window class definition : delete pokemon_1; delete pokemon_2; OF COURSE they're destroyed before I press the button ! SO SORRY about that guys, thank you very much for your time and advices !
  • Aes encryption compatible with openssl cmd

    Solved
    14
    0 Votes
    14 Posts
    2k Views
    M
    @Christian-Ehrlicher Thanks man, this works for me ;) When I find some time I try to find bug in my code. Best Regards, Marek
  • libusb initialization crash

    Unsolved
    2
    0 Votes
    2 Posts
    336 Views
    Pablo J. RoginaP
    @SherifOmran you may need to improve your post, by providing more details. What compiler are you using? Did you download pre-built binaries from the libusb project? If so, are you sure they match the compiler you're using? Are you able to build and run the examples (non Qt apps) provided by the libusb project? Eventually, show the code snippet where you initialize the library
  • I can't find

    Unsolved
    5
    0 Votes
    5 Posts
    417 Views
    D
    @JonB thank you
  • Can someone help me fix this part of a recursive class

    Unsolved
    5
    0 Votes
    5 Posts
    409 Views
    JonBJ
    @AI_Messiah said in Can someone help me fix this part of a recursive class: I get some error message about the type it suggests const, but I add const and it doesn't help When asking for help, you are supposed to copy & paste the error message, which probably shows a line number, and show whatever you tried to resolve. Rather than leaving people to just guess.
  • Alexa with Qt Calendar

    Unsolved
    2
    0 Votes
    2 Posts
    202 Views
    JonBJ
    @Paras You would need to read up on Alexa documentation for this. I don't see anything in Qt which talks about integration with Alexa, other than possibly in Qt Automotive, which is a commercial offering anyway.
  • QScrollArea Not Expanding QCreate

    Solved
    10
    0 Votes
    10 Posts
    500 Views
    C
    @SGaist Sorry for the long reply, I was afk. What you said worked! Really need to watch those layouts, gotta set the QScrollArea to have a QWidget in it, that widget gets the main layout you want and it expands as you need.Thank you for your help and time!
  • fragmentation error when using Qtcpsocket write

    Unsolved
    3
    0 Votes
    3 Posts
    303 Views
    SGaistS
    Hi and welcome to devnet, From the looks of it you are expecting your client to receive all the data you sent in one go. That's not how tcp works. It's up to you cumulate the data you receive contains a full frame. You can use QDataStream and transactions.
  • [SOLVED] Convert #define value to QString?

    10
    0 Votes
    10 Posts
    11k Views
    SGaistS
    Hi, It would be simpler to use a generated header. The double quote escaping won't work on all platforms.
  • How to set enviorment variable from . pro file?

    Unsolved
    6
    0 Votes
    6 Posts
    497 Views
    Christian EhrlicherC
    Since you know when you run your tool with valgrind you can also set this env var before.
  • Associating a file type to my program?

    Unsolved
    15
    0 Votes
    15 Posts
    1k Views
    L
    @JonB I've been trying for 2 days but I couldn't get it to work: main.cpp int main(int argc, char *argv[]) { SingleApplication application( argc, argv, true); mainWindow = new MainWindow(); if (application.isSecondary()) { if (application.arguments().count() == 2) { application.sendMessage( argv[1] ); } return 0; } else { QObject::connect(&application, &SingleApplication::receivedMessage, mainWindow , &MainWindow::slotReceivedMessage); } mainwindow.cpp namespace Win32 { #include "Windows.h" } #define BUFSIZE 4096 void MainWindow::slotReceivedMessage(int instanceId, QByteArray message) { Win32::DWORD retval=0; Win32::BOOL success; Win32::TCHAR buffer[BUFSIZE]; Win32::TCHAR buf[BUFSIZE]; Win32::TCHAR** lppPart={NULL}; // convert char * to wchar_t * const size_t WCHARBUF = 100; wchar_t message_t[WCHARBUF]; Win32::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, message, -1, message_t, WCHARBUF); // get full filename from short filename retval = Win32::GetFullPathName(message_t, BUFSIZE, buffer, lppPart); QString filePath = QString::fromWCharArray(buffer); qDebug() << message; qDebug() << filePath; } Since GetFullPathName needs a wchar_t as input, I have to first convert the char to wchar_t, then convert it to full path name. But when printing out with debug, both the input(message) and output(filePath) are still the same. The GetFullPathName wasn't doing anything. What am I doing wrong?
  • Error "Target xxx.obj does not exist" in pri

    Solved
    8
    0 Votes
    8 Posts
    712 Views
    Andy314A
    @Andy314 I tested a lot over hours to find out whats the problem. Creation of a new projekt or folder projekts gave the same error. Files with old filenames worked, new filenames worked no. The after some changing of "set xxx als active projekt" the Creator tried to compile (or was it reversed) a Cpp file with Python. This gave the hint that with the Creator is something wrong, the active project (resp. the file project relation) was no accepted correctly. Creating of a new workspace and integration my old project solved the problem. There must be a bug in the Creator.
  • QMainWindow: how to get a mouseReleaseEvent after resizing?

    Unsolved qmainwindow resizeevent
    4
    0 Votes
    4 Posts
    2k Views
    JonBJ
    @BwvB I don't know whether installing an eventFilter somewhere would see the mouse release. But I don't see the solutions mentioning that.