Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Polish
  4. Labele i program nieoczekiwanie przerwał pracę.
QtWS25 Last Chance

Labele i program nieoczekiwanie przerwał pracę.

Scheduled Pinned Locked Moved Solved Polish
labelerrorsegmentationfault
3 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Komin
    wrote on 1 Mar 2016, 16:14 last edited by Komin 3 Jan 2016, 16:16
    #1

    Witam, mam problem. Próbuję dodać label do mojego programu. Wydaje mi się, że robię to poprawnie, a po kompilacji pojawia się błąd : Program nieoczekiwanie przerwał pracę. Jak go debuguje pokazuje mi błąd segmentation fault wskazując właśnie na label. Jak usunę label to program się kompiluje i włącza. Może ktoś mi powie co robię źle, bo już przekopałem cały internet i nie potrafię sobie poradzić z tym problemem. Dzięki!

    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QString>
    #include <QMessageBox>
    #include <QLabel>
    #include <QFileDialog>
    #include <QDebug>
    #include <QPixmap>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        this->Inicjalizacja_Interfejsu();
    }
    
    void MainWindow::Inicjalizacja_Interfejsu(){
    
        this->Slidery();
        this->Layouty();
        this->Akcje();
        this->Labele();
    
    
        setWindowTitle("Obsługa Światła");
        setMinimumSize(700, 500);
    
    }
    
    void MainWindow::Slidery(){
    
        Slider1 = new QSlider;
        Slider1->setMaximumSize(50 , 20);
        Slider1->setRange(0 , 1);
        Slider1->setOrientation(Qt::Horizontal);
        Slider1->setStatusTip("Włączanie lampy 1");
        Slider2 = new QSlider;
        Slider2->setMaximumSize(50 , 20);
        Slider2->setRange(0 , 1);
        Slider2->setOrientation(Qt::Horizontal);
        Slider2->setStatusTip("Włączanie lampy 2");
        Slider3 = new QSlider;
        Slider3->setMaximumSize(50 , 20);
        Slider3->setRange(0 , 1);
        Slider3->setOrientation(Qt::Horizontal);
        Slider3->setStatusTip("Włączanie lampy 3");
        Slider4 = new QSlider;
        Slider4->setMaximumSize(50 , 20);
        Slider4->setRange(0 , 1);
        Slider4->setOrientation(Qt::Horizontal);
        Slider4->setStatusTip("Włączanie lampy 4");
    }
    
    void MainWindow::Labele(){
    
       Label1 = new QLabel();
       Label1 -> setText("LOL");
       Label1->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
       Label1->setScaledContents(true);
       Label1->adjustSize();
    }
    
    void MainWindow::Layouty(){
    
       // QHBoxLayout *Pus = new QHBoxLayout;
        //Pus->addWidget(Label1);
        QHBoxLayout *Slide1 = new QHBoxLayout;
        Slide1->addWidget(Slider1);
    
    
    
    
        QGridLayout *gridLayout = new QGridLayout;
          gridLayout->addWidget(Label1 , 0 , 0);
        gridLayout->addLayout(Slide1, 1 , 0);
        gridLayout->addWidget(Slider2 , 3 , 0);
        gridLayout->addWidget(Slider3, 1 , 1);
        gridLayout->addWidget(Slider4, 3 , 1);
    
    
        QWidget *window = new QWidget;
        window->setLayout(gridLayout);
        setCentralWidget(window);
    
    }
    void MainWindow::Akcje(){
    
        QObject::connect(Slider1, SIGNAL(sliderMoved(int)), this , SLOT(Informacja()));
    }
    
    void MainWindow::Informacja(){
    
    
        QMessageBox::information(this,"Info","Lampa 1 włączona");
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      tomasz3dk
      wrote on 1 Mar 2016, 17:09 last edited by tomasz3dk 3 Jan 2016, 17:11
      #2

      Rozumiem, że program przestaje działać na linijce, którą tu w kodzie wykomentowałeś

      //Pus->addWidget(Label1);
      

      Jeśli tak. To zauważ, że Label1 w tej chwili jest jeszcze niezainicjowany. Masz złą kolejność w funkcji Inicjalizacja_interfejsu, jak przeniesiesz wcześniej tworzenie labeli przed tworzenie layoutów to powinno działać:

      void MainWindow::Inicjalizacja_Interfejsu(){
          this->Slidery();
          this->Labele();
          this->Layouty();
          this->Akcje();
       }
      
      K 1 Reply Last reply 1 Mar 2016, 22:19
      1
      • T tomasz3dk
        1 Mar 2016, 17:09

        Rozumiem, że program przestaje działać na linijce, którą tu w kodzie wykomentowałeś

        //Pus->addWidget(Label1);
        

        Jeśli tak. To zauważ, że Label1 w tej chwili jest jeszcze niezainicjowany. Masz złą kolejność w funkcji Inicjalizacja_interfejsu, jak przeniesiesz wcześniej tworzenie labeli przed tworzenie layoutów to powinno działać:

        void MainWindow::Inicjalizacja_Interfejsu(){
            this->Slidery();
            this->Labele();
            this->Layouty();
            this->Akcje();
         }
        
        K Offline
        K Offline
        Komin
        wrote on 1 Mar 2016, 22:19 last edited by
        #3

        @tomasz3dk Wielkie dzięki, pomogło :)

        1 Reply Last reply
        0

        3/3

        1 Mar 2016, 22:19

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved