开发者

Qt - program works when started inside qtcreator, but segfaults if started from the console

开发者 https://www.devze.com 2023-02-22 15:31 出处:网络
I have a strange problem, when i start my Qt program with Qtcreator or in the folder that Qtcreator created (projectname-build-desktop) , it works, but if i want to compile the code with qmake and mak

I have a strange problem, when i start my Qt program with Qtcreator or in the folder that Qtcreator created (projectname-build-desktop) , it works, but if i want to compile the code with qmake and make, i get Segmentation fault on launch. Gdb tells me that :

Program received signal SIGSEGV, Segmentation fault. 0x0089bc37开发者_C百科 in QTableView::verticalHeader() const () from /usr/lib/libQtGui.so.4

the problem comes from a function filling a QtableWidget. How is it possible that it works in one case and not the other ? Here is the function :

void Xml::ajout_ligne_nouveaute (Ui::MainWindow * ui, QString type, QString nom,QString artiste)
{
          is_there_new = true;

          ui->table_new->setEditTriggers(QAbstractItemView::NoEditTriggers);
          ui->table_new->setSelectionBehavior(QAbstractItemView::SelectRows);

            // makes the cells more little
            QHeaderView *verticalHeader = ui->table_music->verticalHeader();
            verticalHeader->setDefaultSectionSize(verticalHeader->fontMetrics().height()+3);


            ui->table_new->setShowGrid(false);


            // auto dimention
            QHeaderView *headers = ui->table_new->horizontalHeader();
            headers->setResizeMode(QHeaderView::Stretch);


            // column number
            ui->table_new->setColumnCount(3);

             // column name
             QStringList header;
             header << "Type" << "Name" << "Artist" ;
             ui->table_new->setHorizontalHeaderLabels ( header );

             // remove left header
             ui->table_new->verticalHeader()->hide();


             // number of current columns
             ui->table_new->setRowCount(offset_courant_nouveaute);


             // one item by cell
             QTableWidgetItem * name  = new QTableWidgetItem(nom, 1000);

             QTableWidgetItem * artist  = new QTableWidgetItem(artiste, 1000);

             QTableWidgetItem * typ  = new QTableWidgetItem(type, 1000);

             ui->table_new->setItem(offset_courant_nouveaute-1, 0, name);
             ui->table_new->setItem(offset_courant_nouveaute-1, 1, artist);
             ui->table_new->setItem(offset_courant_nouveaute-1, 2, typ);


             if(offset_courant_nouveaute%2)
             {
                 QColor * couleur = new QColor( 227, 248, 255, 255);

                 typ->setBackgroundColor(*couleur);
                 artist->setBackgroundColor(*couleur);
                 name->setBackgroundColor(*couleur);
             }

   offset_courant_nouveaute ++;


}


Check LD_LIBRARY_PATH and if needed set it to point QTSDK lib.

0

精彩评论

暂无评论...
验证码 换一张
取 消