Important: Please read the Qt Code of Conduct -

Why can't I see any GUI?

  • I tried to write a program without the help of qtcreator but only command line tools + vim. My problem now is, that there is no gui, and I can't find my mistake:


    #include <QObject>
    #include <QPushButton>
    class BackgroundWorker : public QWidget{
            explicit BackgroundWorker();
            private slots:
                void start();
            QPushButton* mStartButton;


    #include <iostream>
    #include "getInput.hpp"
    #include "backgroundWorker.hpp"
    #include "LIF_network.hpp"
        mStartButton = new QPushButton("Start",this);
        connect(mStartButton, SIGNAL(released()), this, SLOT(start()));
    void BackgroundWorker::start(){
        //main code, qt used to visualize progress


    #include <QApplication>
    #include "backgroundWorker.hpp"
    int main(int argc, char *argv[]){
        QApplication a(argc, argv);
        BackgroundWorker bw;
        return a.exec();

    There should be a button shown, but it is not. In the start() method I draw a QPixmap in qt and show it simply on a QLabel. If I call the start function already in the constructor The QLabel is shown on the screen as a normal window, but there is nothing in the window, but just a part of my desktop background. What am I doing wrong?

  • Hi, I think you need to add; to main.

  • Thank you, now the button in the beginning is showing, but my problem with the QLabels that don't draw anything inside still remains, can you might help me? I need to show a QPixmap filled with Rectangles, but the programme opens a new window, but does not draw anything inside.

    Here is my code:

    void BackgroundWorker::start(){
        int pixelSize = 1;
        //read input data
        int width=0;
        int height=0;
        std::vector<double>bmp = readBMP("/home/jonas/LIF_neural_network_image_recognition/images/plain_landscape_tree.bmp", &width, &height);
        //draw the first window - there is nothing drawn in until the whole start() method ended
        mImages.push_back(new Image(pixelSize,width, height, bmp, "Original"));
        //create the network
        // takes a lot of time
        LIF_network network(width, height);
        //draw result
        std::vector<double> result =  network.getOutput();
        mImages.push_back(new Image(pixelSize, width, height, result, "Result"));


    class Image{
            Image(int tileSize, int sizeX, int sizeY, std::vector<double> values);
            void close();
            int mSizeX, mSizeY, mTileSize;
            QLabel* mLabel;
            QPixmap mPixmap;
            QPixmap drawPixmap(std::vector<double> values);
            std::vector<QRect> mRectangles;
            void initializeRectangles();


    Image::Image(int tileSize, int sizeX, int sizeY, std::vector<double> values):
        mSizeX(sizeX), mSizeY(sizeY), mTileSize(tileSize)
        mPixmap = QPixmap(sizeX*mTileSize, sizeY*mTileSize);
        mLabel = new QLabel("no title");
    void Image::initializeRectangles(){
        mRectangles = std::vector<QRect>();
        for(int y=0; y<mSizeY; ++y){
            for(int x=0; x<mSizeX; ++x){
                QRect rec(x*mTileSize,y*mTileSize,mTileSize,mTileSize);
        delete mLabel;
    QPixmap Image::drawPixmap(std::vector<double> values){
        QPainter p(&mPixmap);
        //QPen pen = QPen(Qt::black, 2);
        //p.setRenderHint(QPainter::Antialiasing, true);
        QBrush brush(Qt::blue);
        //draw every rectangle in its color
        for(size_t i=0; i<values.size(); ++i){
            int colVal = floor(values[i]*255);
            //std::cout << values[i] << std::endl;
        return mPixmap;
    void Image::close(){

    Thank you a lot!

  • @Jonas25 said:

    What happens when you comment out the following line:
    mLabel->setPixmap(drawPixmap(values)); ?
    Does the the label then show the text "no title"?

  • The title is displayed correct, there is just no content in the window. I will upload screenshots:
    after starting the first window but during the computations
    after the computations

  • I'm not completely sure because I can't see all of your code but I think that your application spends a lot of time on some computations in the main thread and thus the GUI doesn't get repainted (freezes). You need to make sure that the main thread (the one that executes the main event loop (return a.exec();)) doesn't get blocked. So you'll have to move your heavy computations to another thread. Take a look at the Mandelbrot example:

Log in to reply