Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.7k Posts
  • why vtable won't work for single file app

    Solved
    6
    0 Votes
    6 Posts
    339 Views
    Thank YouT
    Compiled answer from stack overflow with other links too. Standard C++ doesn't provide support for the dynamic meta-information needed by Qt's meta-object system. Qt solves this problem by providing a separate tool, moc, that parses Q_OBJECT class definitions and makes the information available through C++ functions. Since moc implements all its functionality using pure C++, Qt's meta-object system works with any C++ compiler. Signals and slots in Qt are managed through the moc: meta object compiler. Basically, the moc generates additional C++ code for each class containing the Q_OBJECT macro in order to implement effectively the signals and slots mechanisms. The additional code is then linked to the original class declaration. 29 It's necessary if you define QObject subclasses with the Q_OBJECT macro in a .cpp file. When you do so: qmake must generate rules inside your Makefile to invoke moc on that .cpp file. That special (hackish?) inclusion triggers qmake to do so, and tells it which would be moc's output file (teststring.moc) when invoked on your .cpp. In order to compile moc's output (which is still a bunch of C++ code) the compiler must see your class definition. Otherwise, it will complain that there's no such thing as YourClass::staticMetaObject and similar, because it has no idea that YourClass exists. Typically one defines classes featuring Q_OBJECT in a header file. moc then adds a #include "header.h" into its generated output, and this means moc's output can be happily compiled. But what if your class definition is inside a .cpp? You can't #include a .cpp file in moc's output, as that would give you tons of redefinition errors. Instead, you #include moc's output in your .cpp, so that it gets compiled together and everyone is happy. (This means qmake will only emit one rule saying to run moc, but not another rule telling the compiler to compile moc's output.) From 2. you can also also desume that defining classes with Q_OBJECT in a .h does not require any special inclusion. When Q_OBJECT in xxx.h, after qmake, the system will generate a moc_xxx.cpp with xxx.h in it. When Q_OBJECT in xxx.cpp, after qmake, the system will generate a xxx.moc, and you need to add the .moc file into the .cpp file. LINKS http://doc.qt.io/qt-5/why-moc.html https://doc.qt.io/qt-5/moc.html If you got more add here I will edit and make single answer
  • 0 Votes
    15 Posts
    17k Views
    I
    @Smoketurtt said in Error: This version of PyQt5 and the commercial version of Qt have incompatible licenses.: Looks like configure.py got updated Looks like configure.py got updated AGAIN. I comented out lines from 2674 to 2677. # Common checks. # if introspecting and target_config.qt_licensee not in OPEN_SOURCE_LICENSEES and ltype == 'GPL': # error( # "This version of PyQt5 and the commercial version of Qt have " # "incompatible licenses.")
  • Infinite loop with regex (non reproducible in command line application)

    Solved
    8
    0 Votes
    8 Posts
    819 Views
    JonBJ
    @pgiovanni said in Infinite loop with regex (non reproducible in command line application): No, it does not. it works without qt involved man. You want proof? A more productive initial reaction than this would be "I wonder if these guys actually know what they're talking about, I'll go triple-check my code in case..." :) <- Smiley
  • filesystem in C++17 and Q_OBJECT conflicts

    Solved
    18
    0 Votes
    18 Posts
    3k Views
    C
    i have also faced same thing while compilation. .
  • VideoOutput with filters in Qt6

    Unsolved
    1
    1 Votes
    1 Posts
    184 Views
    No one has replied
  • Message box makes program to exit

    Solved
    9
    0 Votes
    9 Posts
    718 Views
    D
    @JonB oh fuck, that line was forgotten there :( I am so sorry for wasting your time for suck a dummy thing . Thanks a lot!
  • QWindow OpenGL Tearing

    Unsolved qwindow opengl vsync glitch qsurfaceformat
    5
    0 Votes
    5 Posts
    1k Views
    SGaistS
    It should be supported indeed. Did you try with a more recent release of Qt ? Like 5.15 or even 6.2 ?
  • Help for QString formatting

    Unsolved
    3
    0 Votes
    3 Posts
    359 Views
    M
    @eyllanesc said in Help for QString formatting: @markolino_it Use https://doc.qt.io/qt-5/qstring.html#arg Thanks a lot. I share the solution : QString comando= QString("at+cmgs=\"%1\"\r").arg(myList->at(myIndex)); I am not familiar with c++ thanks a lot !
  • How to display Gstreamer video using vaapisink inside QVideoWidget by QMediaPlayer?

    Unsolved
    4
    1 Votes
    4 Posts
    869 Views
    SGaistS
    The common point between the two is the use of the vaapisink hence my suggestion.
  • 0 Votes
    24 Posts
    6k Views
    SGaistS
    Looks like you rather need to store that information in some sort of database or configuration file(s).
  • Layout problem

    Solved
    14
    0 Votes
    14 Posts
    631 Views
    SGaistS
    @SPlatten said in Layout problem: clsQtLayout Please reconsider the naming of your class. They make things harder to understand for no benefits. Your clsQtLayout is in fact a QWidget. The Qt layout classes are not QWidgets. This name is confusing at best.
  • When using opencv, the Qt project crashes

    Unsolved opencv crash app
    6
    0 Votes
    6 Posts
    2k Views
    SGaistS
    I am wondering whether there's some bad interaction between the 2017 build of Qt and your 2019 build of OpenCV. There should not as VS 2019 is backward compatible with 2017.
  • 0 Votes
    9 Posts
    1k Views
    P
    @JonB it works bro thank you problem fixed when i tried this before it doesn't open the window at all ... just flashing but now i understand why it's working Thank you <3
  • MacOS dylib plugin loading path changes from Qt 5.15 to Qt 6.2

    Solved
    8
    0 Votes
    8 Posts
    673 Views
    Q
    @artwaw @SGaist I think it works now if I place it in the root Frameworks folder. Using ottol on the lib printed: Load command 12 cmd LC_LOAD_DYLIB cmdsize 56 name @loader_path/libsteam_api.dylib (offset 24) time stamp 2 Thu Jan 1 01:00:02 1970 current version 1.0.0 compatibility version 1.0.0 Load command 13 cmd LC_LOAD_DYLIB cmdsize 72 name @rpath/QtQuick.framework/Versions/A/QtQuick (offset 24) time stamp 2 Thu Jan 1 01:00:02 1970 current version 6.2.1 compatibility version 6.0.0 Load command 14 Thanks for your help! Have a great weekend <3
  • How to add footer in QTextTable?

    Unsolved
    5
    0 Votes
    5 Posts
    841 Views
    D
    This, looks like, works: [image: 787f7168-71d1-45c2-8a96-d5961104c648.gif] All I did is subtracted the reqHeight from heightLeft in for as it was generating an additional row. void Window::createDocument(){ int row = 200, column = 3; QTextCursor cursor(document); cursor.insertTable(1, 3, format(false)); addHeader(cursor); QFontMetricsF metrics(font()); qreal headerHeight = metrics.boundingRect(QRectF(0,0,0,0), QFont::Bold, "Column 1").height() + 2.0; // +2 for border auto pageSize = printer->pageRect(QPrinter::DevicePixel).size(); qreal heightLeft = pageSize.height() - 2 * headerHeight; // 2* for header and footer QRectF col1Rect(0,0, pageSize.width() * .8, fontMetrics().height()); QLocale locale; QTextBlockFormat rightAlign; rightAlign.setAlignment(Qt::AlignVCenter | Qt::AlignRight); for (int r = 1; r < row; r++) { QString text; if(r % 2 == 0) text = "Long long Long long Long long Long long Long long Long long Long long Long long Long long text"; else text = "Row " + QString::number(r) + " Column " + QString::number(10); auto reqHeight = metrics.boundingRect(col1Rect, Qt::AlignVCenter|Qt::AlignLeft|Qt::TextWordWrap, text).height(); heightLeft -= reqHeight; if(heightLeft < 0){ cursor.currentTable()->removeRows(cursor.currentTable()->rows()-1, 1); cursor.currentTable()->appendRows(1); cursor = cursor.currentTable()->rowStart(cursor); cursor.movePosition(QTextCursor::NextRow); addFooter(cursor); heightLeft = pageSize.height() - 2*headerHeight - reqHeight; // here's an additional reqHeight subtraction cursor.movePosition(QTextCursor::End); cursor.insertTable(1, 3, format()); addHeader(cursor); } cursor.currentTable()->appendRows(1); cursor = cursor.currentTable()->rowStart(cursor); cursor.movePosition(QTextCursor::NextRow); for (int c = 0; c < column; c++) { if(c == 0) cursor.insertText(text); else { cursor.setBlockFormat(rightAlign); cursor.insertText(locale.toString(1000)); } cursor.movePosition(QTextCursor::NextCell); } } } BUT why? Why does it work? Why do I have to subtract that height for subsequent pages? This technique probably will make earlier failed attempt of adding header in this way successful.
  • Setup conan with Qt 6 error

    Unsolved conan
    1
    0 Votes
    1 Posts
    295 Views
    No one has replied
  • Pushbutton problem

    Solved
    11
    0 Votes
    11 Posts
    858 Views
    A.A.SEZENA
    Maybe you should check qApp->focusWidget() when handling Qt::Key_Enter and Qt::Key_Return events in keyPressEvent.
  • Conditional breakpoint?

    Unsolved
    16
    0 Votes
    16 Posts
    1k Views
    SPlattenS
    @JonB , I'm not sure that the widget itself is being destroyed at all, only that it isn't in the list I appended it to when I go to add the next widget.
  • how to type an interface without a ui editor ??

    Solved ui form
    7
    0 Votes
    7 Posts
    715 Views
    timob256T
    i mace this :) #include "dialogokno.h" DialogOkno::DialogOkno(QWidget *parent) : QWidget(parent) { // обявл элементы gl_layaout[0] = new QGridLayout(parent); gl_layaout[1] = new QGridLayout(parent); gl_layaout[2] = new QGridLayout(parent); gl_layaout[3] = new QGridLayout(parent); l_label[0] = new QLabel(parent); l_label[1] = new QLabel(parent); l_label[2] = new QLabel(parent); le_edit[0] = new QLineEdit(parent); le_edit[1] = new QLineEdit(parent); le_edit[2] = new QLineEdit(parent); le_edit[3] = new QLineEdit(parent); le_edit[4] = new QLineEdit(parent); le_edit[5] = new QLineEdit(parent); le_edit[6] = new QLineEdit(parent); // настройки элеметов (стилизация) // заполнение элементов l_label[0]->setText("hla_global"); l_label[1]->setText("hla_local"); l_label[2]->setText("logger"); le_edit[0]->setText("server_ip_global"); le_edit[1]->setText("server_port_global"); le_edit[2]->setText("server_port_local"); le_edit[3]->setText("server_port_local"); le_edit[4]->setText("log"); le_edit[5]->setText("log_period_ms"); le_edit[6]->setText("log_size_in_mb"); //разложение элементов по группам gl_layaout[0]->addWidget(l_label[0], 0, 0, 1, 1); gl_layaout[0]->addWidget(le_edit[0], 1, 0, 1, 1); gl_layaout[0]->addWidget(le_edit[1], 2, 0, 1, 1); gl_layaout[1]->addWidget(l_label[1], 0, 0, 1, 1); gl_layaout[1]->addWidget(le_edit[2], 1, 0, 1, 1); gl_layaout[1]->addWidget(le_edit[3], 2, 0, 1, 1); gl_layaout[2]->addWidget(l_label[2], 0, 0, 1, 1); gl_layaout[2]->addWidget(le_edit[4], 1, 0, 1, 1); gl_layaout[2]->addWidget(le_edit[5], 2, 0, 1, 1); gl_layaout[2]->addWidget(le_edit[6], 3, 0, 1, 1); gl_layaout[3]->addLayout(gl_layaout[0], 0,0); si_spacer[0] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); gl_layaout[3]->addItem(si_spacer[0],0,1); gl_layaout[3]->addLayout(gl_layaout[1], 0,2); si_spacer[1] = new QSpacerItem(120, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); gl_layaout[3]->addItem(si_spacer[1], 0, 3); si_spacer[2] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding); gl_layaout[3]->addItem(si_spacer[2],1,0); gl_layaout[3]->addLayout(gl_layaout[2], 2,0); si_spacer[3] = new QSpacerItem(20, 82, QSizePolicy::Minimum, QSizePolicy::Expanding); gl_layaout[3]->addItem(si_spacer[3],3,0); this->setLayout(gl_layaout[3]); } DialogOkno::~DialogOkno() { } [image: 74055803-3857-4615-9813-102ca84f283d.png]
  • Is there a way to have speech to text in Qt C++ ?

    Unsolved
    6
    1 Votes
    6 Posts
    598 Views
    JoeCFDJ
    @JKSH Good stuff.