跳到內容

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.4k 主題 456.4k 貼文
  • QScriptEngine memory leak ??

    Unsolved
    6
    0 評價
    6 貼文
    565 瀏覽
    C
    @Martin-Wells said in QScriptEngine memory leak ??: sorry ,Does qt5.15.2 QScriptEngine support let? Evidently not. Not too surprising given that QtScript is long deprecated. Setting the value to undefined (or even an empty string) should give the Javascript garbage collector a chance. Does this scratch your itch? #include <QCoreApplication> #include <QObject> #include <QScriptEngine> #include <QString> #include <QDebug> class Test: public QObject { Q_OBJECT public: Test(QObject *p = nullptr): QObject(p) { } ~Test() { } public slots: QString string() { return QString(10*1024*1024, 'x'); } }; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QScriptEngine engine; Test *test = new Test(qApp); QScriptValue objectValue = engine.newQObject(test); engine.globalObject().setProperty("Test", objectValue); // At time 0 engine.evaluate("var a = Test.string()"); if(engine.hasUncaughtException()) { qDebug()<<engine.uncaughtException().toString(); } // At some time later qDebug() << "The string length is:" << engine.evaluate("a.length").toNumber(); // and later still engine.evaluate("a = undefined"); if(engine.hasUncaughtException()) { qDebug()<<engine.uncaughtException().toString(); } qDebug() << "The string length is:" << engine.evaluate("a.length").toNumber(); return a.exec(); } #include "main.moc" Why do you want a couple of GB in a Javascript environment? Please use the </> tool in the editor when posting code.
  • QSqlDatabase "Driver not loaded" 🤔🤨

    已移動 Solved
    13
    0 評價
    13 貼文
    1k 瀏覽
    Christian EhrlicherC
    @SEB-MARS As you can see the Mysql plugin is not available - you have to compile it by yourself (blame MySQL, not Qt) as described here.
  • My custom widget does not appear in Qt Designer

    Solved
    8
    0 評價
    8 貼文
    748 瀏覽
    J
    @Christian-Ehrlicher I found the problem: I was placing a debug version of the plugin!! Now that I compiled with release it appears in Qt Designer!! GREAT!! Thanks!!
  • BUMP "Go to slot" issue...

    Unsolved
    2
    0 評價
    2 貼文
    157 瀏覽
    Pl45m4P
    @AnneRanch The first warning says it all... Your copied file is not part of your project. If your current file is in the same directory as your removed file was, simply add the name of your new, copied mainwindow_Bluetooth.cpp to your pro in the cpp section. Edit: The second warning even says that this file is not in your project dir. Better move it to the place where you removed the "old" code file
  • QMainWindow opens in the screen where the mouse is currently in

    Unsolved
    8
    0 評價
    8 貼文
    2k 瀏覽
    G
    It is an error from consumer POV, because it does that even if instructed not to, if originally was instrcted to be open on "main" screen. Worse, using Qt functionality to open Window on particular display is ignored for display "0.0" . Funny, that after this numbering of screens for app changes. If several applications are started, each got screen number 0 as they were launched on. Imagine a multiscreen setup where several windows have to be opened on separate screens. It's a hardware monitoring station, after clicking the icon. I encounter this effect since Qt 4.8.7 that QMainWindow always jumps to the mouse's location, on Xorg only. A "hack" to put start icon on right screen doesn't work because user is able to move cursor faster than app is launched. Neither Windows nor Wayland behavour offer the same, so I supect that X11 window managers are the culprit.
  • Create text display with syntax highlighting

    Unsolved help textarea syntax highligh
    2
    0 評價
    2 貼文
    405 瀏覽
    jsulmJ
    @IGaming73 See https://doc.qt.io/qt-6/qsyntaxhighlighter.html and https://doc.qt.io/qt-6/qtwidgets-richtext-syntaxhighlighter-example.html
  • How to fix strected image label in a layout?

    Unsolved
    8
    0 評價
    8 貼文
    748 瀏覽
    B
    @Rangerguy128 Yes, as @JonB replied above (also need to write codes). But I don't see that makes any sense. When you change scaledcontents to false, it won't keep the image size when it is true, it just show the actual size. So if you are not going to keep the image in its actual size, you need to write codes as @mpergand shows you.
  • 0 評價
    3 貼文
    379 瀏覽
    J
    @Pl45m4 only one thing: which project type should I create in Visual Studio? Qt Designer custom widget? do we need to export the widget? __declspec(dllexport)?? The only problem is the examples are for use in Qt Creator I think while I am in Visual Studio... is there a VS example? How can I find the value of the macros like $$[QT_INSTALL_PLUGINS] and ${INSTALL_EXAMPLEDIR}?
  • Creating a new widget class over using a stackedWidget?

    Solved
    2
    0 評價
    2 貼文
    213 瀏覽
    Pl45m4P
    @he_R0 Hi and welcome :) should I always be using a StackedWidget, or are there cases where creating a new designer form class is better? As often: it depends... Do you want to have your widgets at the same place and showing only one at a time or do you want them to be next to each other (or in a new window) and showing/using multiple at once? A QStackedWidget is one of Qt's plenty container widgets... there are also widgets like QTabWidget or different Model/Views. QStackedWidget works like a book with pages... you can flip the pages in-place, but you can only see the currentWidget. I didn't want to make it messy and have too many stackedWidgets embedded into each other Multiple or cascading QStackedWidgets?! Mh, that already sounds like bad design. Can't see why you need to do this, since you can simply add a new widget to the only QStackedWidget. There is no need to embed a new QStackedWidget and fill it with content widgets... there might be some edge cases, where it could be viable, but I can't see a reason why you need to do this right now ;-) Since we know nothing about your app, you should develop a feeling for which design suits your app the best. Is it more technical? like some simple inputs/outputs, controls and some processing going on in the background. Or do you have some fancy, modern app in mind, with lots of toolbars, side widgets, menus etc.? using QT for a personal project. Because of this, you are not limited and you can try out few things... if you have a more concrete sketch of your app feel free to ask again :) Happy coding :)
  • QPainter does not work

    Unsolved qpainter qline qimage qwidget qpaintevent
    18
    0 評價
    18 貼文
    2k 瀏覽
    C
    @Joe-von-Habsburg My example recast with a changing background: // widget.h #ifndef WIDGET_H #define WIDGET_H #include <QWidget> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); // QWidget interface protected: void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void paintEvent(QPaintEvent *event); private slots: void setBackground(); private: QImage mBackground; QPointF mFrom; QPointF mTo; }; #endif // WIDGET_H // widget.cpp #include "widget.h" #include <QPaintEvent> #include <QPainter> #include <QLinearGradient> #include <QRandomGenerator> #include <QTimer> #include <QDebug> Widget::Widget(QWidget *parent) : QWidget(parent) , mBackground(500, 500, QImage::Format_RGB32) { setBackground(); QTimer *t = new QTimer(this); connect(t, &QTimer::timeout, this, &Widget::setBackground); t->start(1000); } Widget::~Widget() { } void Widget::mousePressEvent(QMouseEvent *event) { mFrom = event->position(); mTo = mFrom; } void Widget::mouseReleaseEvent(QMouseEvent *event) { mTo = event->position(); update(); } void Widget::paintEvent(QPaintEvent *event) { QPainter p(this); p.drawImage(event->rect(), mBackground); if (mFrom != mTo) { QPen pen(Qt::red); pen.setWidth(3); p.setPen(pen); p.drawLine(mFrom, mTo); } p.end(); } void Widget::setBackground() { QPainter p(&mBackground); const QRectF rectf(mBackground.rect()); QLinearGradient grad(rectf.topLeft(), rectf.bottomRight()); grad.setColorAt(0, QColor::fromRgb(QRandomGenerator::global()->generate())); grad.setColorAt(1, QColor::fromRgb(QRandomGenerator::global()->generate())); p.fillRect(mBackground.rect(), QBrush(grad)); p.end(); update(); }
  • bpftrace and printing content of QString

    Unsolved
    2
    0 評價
    2 貼文
    153 瀏覽
    SGaistS
    Hi, Did you also contact the bpftrace folks about that request ?
  • 此主題已被刪除!

    Unsolved
    11
    0 評價
    11 貼文
    111 瀏覽
  • QWebSocket doesn't detect lost connection?

    Solved
    2
    0 評價
    2 貼文
    169 瀏覽
    JonBJ
    @ocgltd I would say "Yes" to first question and "No" to second. You might like to look at forum.qt.io/topic/106382/how-to-check-server-life-using-qwebsocket-ping-pong.
  • Desktop-systray example issue on MAC

    Unsolved
    14
    1 評價
    14 貼文
    2k 瀏覽
    A
    @alzix @achak Hello guys! Did you find any solution for this problem? I have met same problem on Qt6.6.2 and MacOS 14.1 Sonoma. When I exit my app from system tray menu (by calling qApp->exit(0)), I must click on main widget or system tray icon to fully exit app. But, when I call qApp->exit(0) from main widget -> app is exiting normally. Also app exits normally by clicking Quit in dock menu or by Ctrl+Q. Same code on Windows works as expected: app exits.
  • issue with QChartView (v.5.15.12)

    Unsolved
    5
    0 評價
    5 貼文
    617 瀏覽
    JonBJ
    @lano1106 I started to have a go at looking at your question. But there is a distinct lack of a full example so I have no idea about your situation/what you are trying to do. What UI do you have? Where is the chart view? How/why does your chart view receive a resize event? From code, from the user resizing the containing widget? FWIW I just created a QWidget and put a QChartView on it. no viewport()->resize(). When it shows initially I get QChartView: QSize(178, 78) , chart: QRectF(0,0 178x78) viewport: QSize(178, 78) and if a drag-resize the widget I get QChartView: QSize(296, 225) , chart: QRectF(0,0 296x225) viewport: QSize(296, 225) So my viewport is always same as chart view/chart size. I suggest you create and show a minimal example. Btw I do not fully understand all the intricacies of the GraphicView but I would have expected that changing the Scene rect would also modify its viewport size as well. Changing QGraphicsScene size/rect does not modify either QGraphicsView or its viewport, nor should it. Just in case you are doing so, calling QChart::resize() does not affect either QChartView or its viewport.
  • The QOpenGLWidget and QLabel updates frequently, resulting in memory leaks

    Unsolved
    2
    0 評價
    2 貼文
    131 瀏覽
    Christian EhrlicherC
    @MissingDream Please properly format your code with the code tags ('</>' button) so we can read it.
  • load image report Corrupt JPEG data: premature end of data segment

    Unsolved
    9
    0 評價
    9 貼文
    2k 瀏覽
    C
    @zhouyinlong Intermittent behaviour would have been good to mention in your first post. All your example images show an image corrupted from the same place. If you give Qt the same image data every time then you get the same result every time. If it sometimes works and sometimes does not then you have to consider that the input image is changing (long before any more abstract causes). For example, you are grabbing the image over the network and truncating it accidentally by mishandling the transfer, or you are trampling over a buffer with out-of-bounds memory accesses. We cannot see your actual code or input image.
  • 此主題已被刪除!

    Unsolved
    1
    0 評價
    1 貼文
    3 瀏覽
    尚無回覆
  • QSplitter when trying to grab drag handle end up getting the ui elements underneath it (mac)

    Unsolved
    1
    0 評價
    1 貼文
    138 瀏覽
    尚無回覆
  • 0 評價
    3 貼文
    361 瀏覽
    J
    @Pl45m4 Thanks!