Skip to content
  • 0 Votes
    6 Posts
    818 Views
    JonBJ

    @BigBen

    Store them in a container yourself as you create them: QList<QLabel *> labels; for (int i = 0; i < 10; i++) { QLabel *label = new QLabel; someLayout->addWidget(label); labels.append(label); } Assign them an objectName for future reference to recall an individual one: QList<QLabel *> labels; for (int i = 0; i < 10; i++) { QLabel *label = new QLabel; label->setObjectName(QString("label_%1").arg(i)); someLayout->addWidget(label); } QLabel *label_2 = someParentWidget->findChild<QLabel *>("label_2"); Collect them all via findChildren(): QList<QLabel *> labels = someParentWidget->findChildren<QLabel *>();
  • 0 Votes
    9 Posts
    985 Views
    Swati777999S

    @jsulm said in Cout in a loop for QLabel Widgets:

    @Swati777999

    Names[ii] = new QLabel(QString("Name %1").arg(ii));

    Works perfectly! Thanks.

  • 0 Votes
    3 Posts
    522 Views
    A

    The problem was in the Windows firewall. I still don't understand why this was affecting the sound, but disabling the firewall did the trick.

  • 0 Votes
    9 Posts
    3k Views
    M

    Thank you all for the valuable information you have given me!

    In the end I got around the inability to use the main event loop by running my new part on a separate thread, with this pattern:

    QThread myThread;
    MyNewPart newPart;
    newPart.moveToThread(&myThread);
    /* Connect(...) QThread::started -> MyNewPart::run*/
    myThread.start();

    Everything works without changing the code :)

  • 0 Votes
    3 Posts
    2k Views
    F

    @SGaist
    Thanks for answering.
    Basically, I am separating rendering and updating to have fixed-timestep updating (for physics etc) as well as as-fast-as-possible rendering with time interpolation. (Heavily heavily inspired from Gaffer on Games article)
    My code looks as follows (only slightly simplified):

    ... within my OpenGLContext void GLWindow::gameLoop() { const double delta = 1.0 / fixedUpdatesPerSecond; auto time = QDateTime::currentMSecsSinceEpoch(); double accumulated = 0.0; while (! this->terminate) { auto newTime = QDateTime::currentMSecsSinceEpoch(); double frameExecution = tdiff(time, newTime); time = newTime; accumulated += frameExecution; while (accumulated >= delta) { // Handle user input / system polling //However, since Qt has event driven polling, let's just call processEvents and then handle any input events by putting their results into a map. QCoreApplication::processEvents(); // Update our states this->updateState(delta); accumulated -= delta; } this->render(accumulated / delta); } }

    In the same class, I have updateState and render:

    void MyGL::updateState(float delta) { //... Bunch of commented-out code to make sure base loop works first if(myKeys.at(Qt::Key_W)) { cam->translateAlongForward(delta * 3.0); cam->update(); } } void MyGL::render(float aheadAlphaPercent) { this->update(); } void MyGL::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); lambertShader->setViewProj(cam->matrix()); // a lot of other drawing stuff }

    I know that my rendering code itself works because I initially tested it by just using a QTimer.

    Instead, I now do the following:

    ...in main... QApplication a(argc, argv); QSurfaceFormat::setDefaultFormat(format); MainWindow w; w.show(); w.start(); //return a.exec(); // ^Dont^want^to^uncomment^this^ ... MainWindow::start (MainWindow is QMainWindow subclass)... uiElements->glWindow->gameLoop(); //glWindow is subclass of OpenGLContext

    As you can see, I tried to avoid calling Qt's blocking event loop in QApplication::exec, but am still polling events. However, this doesn't work properly, as described in my first post.

  • 0 Votes
    7 Posts
    2k Views
    MCamM

    @pauledd
    I would recommend using the build-in QThread mechanism to interrupt a thread:

    public slots: void doWork() { forever() { ... if ( QThread::currentThread()->isInterruptionRequested() ) { return; } ... } }

    You can add this check to your SPI loop multiple times but avoid to call it too often, according to the dokumentation.
    Add something like this to your MainWindow-Instance:

    public slots: void cancel() { if( thread.isRunning()) { thread.requestInterruption(); } }

    and connect this Slot to some Cancel-Button.

  • 0 Votes
    6 Posts
    2k Views
    pauleddP

    Thanks a lot for your suggestions. I ended up doing it with the vectors because it was most elegant for my brain...

    *.h

    QVector<QLabel*> labels;

    *.cpp

    for(int i=0;i<24;i++){ labels.append(new QLabel(QString::number(23-i))); } for(int i=0;i<labels.size();i++){ labels[i].setAlignment(Qt::AlignCenter); }

    and then the same for the checkboxes. I guess the vector saved about 100 lines of code.

    Works like a charm :)

    Bildschirmfoto_2019-10-30_13-42-22.png

  • 0 Votes
    7 Posts
    2k Views
    C

    @jsulm U are da king!

    I am dealing with QML for months, and just learning the property variables! That kinda saved my life mate!
    Thank you very much!

  • 0 Votes
    3 Posts
    4k Views
    ?

    Thanks for your answer, unfortunately this part of my code is executed in a class that inherits from QMainWindow, I don't have access to the QApplication.

    Edit:

    It works using QCoreApplication::processEvents() instead.

  • 0 Votes
    12 Posts
    4k Views
    J.HilkJ

    @kshegunov said in increasing QList<QStringList> contents twice!:

    if it looks like a duck, swims like a duck, and quacks like a duck

    s

    Slight thread derail, but I would say the op's question general is answered .

  • 0 Votes
    8 Posts
    2k Views
    SGaistS

    Again, remove the insert line and change the setText call to setText(texto). You'll avoid useless operations and your code will be cleaner.

  • 0 Votes
    10 Posts
    3k Views
    CybeXC

    @VRonin a suggest read is a SO post

    As mentioned earlier aswel, I will use this iterator (first time :p)

    Thanks for all the help!

  • SmoothedAnimation not looping

    Moved Unsolved QML and Qt Quick
    2
    0 Votes
    2 Posts
    1k Views
    J

    @Tinnin said in SmoothedAnimation not looping:

    SmoothedAnimation

    You have from and to but nothing to make x Go back to zero Make a SequentialAnimation and have your steps in there. .

    from: 0 to: -(groundImage.spriteWidth)

    then

    from: -(groundImage.spriteWidth) to: 0

    put your loop on your SequentialAnimation and not on your SmoothedAnimation same with running and the id that I am guessing this is how you trigger,

  • 0 Votes
    2 Posts
    2k Views
    p3c0P

    @Mark81
    The cellHeight when changes updates the cellWidth in this line:

    cellWidth: Math.min(parent.width, parent.height) == parent.width ? parent.width / 3 : cellHeight

    this cellWidth change re-evaluates the binding and updates the cellHeight in this line:

    cellHeight: Math.min(parent.width, parent.height) == parent.width ? cellWidth : parent.height / 2

    And this goes on foreever and hence the error.

    By the way, how to center the GridView content? It fills the available space from left-to right.

    How do you want it to appear ? Can you share some image ?

  • 0 Votes
    2 Posts
    26k Views
    CharbyC

    The binding loop comes from the container item where you ask the container to be of the size of its content whereas you size its content according to the parent size.

    You can either define the container dimensions as followed :

    width: dataInputField.width height: outputText.height + dataInputField.height

    but I would feel more natural to do the other way around : define the container dimension and then compute child element dimension according to the parent.

  • 0 Votes
    3 Posts
    1k Views
    O

    @Chris-Kawa yes that is an option, but what if erros appear while the processes running? If i put the MessageBox after the for-loop i need a mechanism to check if there was an error or not. therefore i wanted to use Signal and Slot for the process.

    EDIT
    i solved it. I wrote a function in which i check if there where errors with readAllStandardError and if the size of it is zero, no error appeared and the show the message box.