Hello,

I have a problem.How I must add QMainWindow to my code, because the error is:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method menuBar() is undefined for the type Calendar

package Kalendarz;

import com.trolltech.qt.gui.*;
import com.trolltech.qt.core.*;
import com.trolltech.qt.gui.QMenu;
import com.trolltech.qt.gui.QAction;
import com.trolltech.qt.gui.QApplication; 
import com.trolltech.qt.gui.QColor;
import com.trolltech.qt.gui.QIcon;
import com.trolltech.qt.gui.QMainWindow; 
import com.trolltech.qt.gui.QMenuBar;
import com.trolltech.qt.gui.QPlainTextEdit; 
import com.trolltech.qt.gui.QTextDocument;
import com.trolltech.qt.gui.QTextEdit;
import com.trolltech.qt.gui.QToolBar;
import com.trolltech.qt.gui.QWidget;

public class Calendar extends QWidget 
{
    private QGroupBox previewGroupBox;
    private QGridLayout previewLayout;
    private QCalendarWidget calendar;

    private QMenu helpMenu;
    private QAction aboutAct;

    public Calendar() {
        createPreviewGroupBox();

        QGridLayout layout = new QGridLayout();
        layout.addWidget(previewGroupBox, 0, 0);
   
        layout.setSizeConstraint(QLayout.SizeConstraint.SetFixedSize);
        setLayout(layout);

        previewLayout.setRowMinimumHeight(0, calendar.sizeHint().height());
        previewLayout.setColumnMinimumWidth(0, calendar.sizeHint().width());

        setWindowIcon(new QIcon("images/cal.png"));
		setWindowTitle(tr("Kalendarz"));
		
        QMenuBar menuBar = new QMenuBar();

		createMenus(); 
    }
    private void createActions()
	{
        aboutAct = new QAction(new QIcon("/help-16x16.png"), tr("&O programie"), this);
        aboutAct.setShortcut(tr("F12"));
        aboutAct.setStatusTip(tr("Informacje"));
        aboutAct.triggered.connect(this, "about()");
	}
    private void createMenus()
    {
        helpMenu = menuBar().addMenu(tr("&Pomoc"));
        helpMenu.addAction(aboutAct);
    }
	private void createPreviewGroupBox() {
        previewGroupBox = new QGroupBox(tr("Preview"));

        calendar = new QCalendarWidget();
        calendar.setMinimumDate(new QDate(1900, 1, 1));
        calendar.setMaximumDate(new QDate(3000, 1, 1));
        calendar.setGridVisible(true);

        previewLayout = new QGridLayout();
        previewLayout.addWidget(calendar, 0, 0, Qt.AlignmentFlag.AlignCenter);
        previewGroupBox.setLayout(previewLayout);

    }
    public void about()
    {
    	QMessageBox.about (this,"O programie","<I></I><center><b><font color=#004faf>Text+</font></b><br /><br /><BIG>Wersja 1.0.0</BIG> " +
    			"<p></p>Copyright &copy;2009 by Kevin Ostajewski<small><p><small>Wszelkie prawa zastrzeżone.</p>" +
    			"<p>Nieautoryzowane rozpowszechnianie elementów <br />programu jest łamaniem praw autorskich.</p></small></center>");
    }
    public static void main(String args[]) {
        QApplication.initialize(args);

        Calendar widget = new Calendar();
        widget.show();

        QApplication.exec();
    }
}

Well, to get rid of that error, don't call methods that do not exist

helpMenu = menuBar().addMenu(tr("&Pomoc"));

when I change to :

public class Calendar extends QMainWindow

it work but the calendar does't work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.