Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Mouse ShortCut menu on DialogWindows?



  • Hi,
    Normally I use ShortCut Menu on Mainwindow like below code
    In constructor:

    ui->tVDetay->setContextMenuPolicy(Qt::CustomContextMenu);
               connect(ui->tVDetay, SIGNAL(customContextMenuRequested(const QPoint&)),
                          this, SLOT(ShowContextMenuTalep(const QPoint&)));
    

    And the pordedure is:

    void StokBilgiGiris::ShowContextMenuTalep(const QPoint& pos)
    {
        QPoint globalPos = ui->tVDetay->mapToGlobal(pos);
    
        QMenu myMenuX;
    
        myMenuX.addAction("Stok Bilgisi Göster");
    
    
        QAction* selectedItem = myMenuX.exec(globalPos);
    
        // Hiçbir şey tıklanmazsa hata vermesin diye... :)
    
        if (selectedItem == nullptr) return;
    
    
        QModelIndex index;
        index = ui->tVDetay->currentIndex();
    
    
        if(!index.isValid())
        {
            QMessageBox::warning(this,"Seçim Hatası", "Seçili bir satır olması gerekir!");
            return;
        }  
    
        if (selectedItem->text() == "Stok Bilgisi Göster" )
        {
    
        }
    
    
    
    }
    
    

    But I don' know why Below line has error

    QMenu myMenuX;

    And teh error message is:

    D:\Belgeler\Qt\CSI_Yonetim\stokbilgigiris.cpp:65: error: variable has incomplete type 'QMenu'
    D:\ProgramFiles\Qt\5.10.1\msvc2017_64\include\QtWidgets\qlineedit.h:54: forward declaration of 'QMenu'

    What is the problem?

    Regards,
    Mucip:)


  • Lifetime Qt Champion

    Hi,

    You are missing #include <QMenu>.

    The incomplete type error means that you are missing the definition of the class which usually means that you didn't include the corresponding header.



  • Hi SGaist,
    Thanks. Yes.
    I confused because there isn't any error like missing library or like?

    Regards,
    Mucip:)


  • Lifetime Qt Champion

    You won't have any linker error since the code cannot be compiled because of the missing include.


Log in to reply