Note that there are some explanatory texts on larger screens.

plurals
  1. POQT hangs my toolbar and its buttons
    primarykey
    data
    text
    <p>I've created 2 classes, each:</p> <ol> <li>has <code>QWidget</code> as a parent</li> <li>has <code>Q_OBJECT</code> macros</li> <li>inits some actions, creates menubar and toolbar, and connects actions to them</li> </ol> <p>Then I created the main program file, created <code>QMainWindow</code>, and init my two classes by <code>qmainwnd</code> pointer.</p> <p>And what I've got - menu works, the second toolbar works, but the first toolbar (created by class 1) doesn't respond to mouse clicks.</p> <p>What happed with it? Why I can not even move this first toolbar or click its buttons?</p> <p>Here a sample:</p> <p><a href="http://pastebin.com/Qu7ibFqy" rel="nofollow">main.cpp</a></p> <pre><code>#include &lt;QApplication&gt; #include &lt;QMainWindow&gt; #include "CModDocument.h" #include "CModEditor.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow wnd; // init CA CModDocument a(&amp;wnd); // init CB CModEditor b(&amp;wnd); wnd.show(); return app.exec(); } </code></pre> <p><a href="http://pastebin.com/XQwnjv8V" rel="nofollow">CModDocument.h</a></p> <pre><code>#ifndef CMODDOCUMENT_H #define CMODDOCUMENT_H #include &lt;QWidget&gt; QT_BEGIN_NAMESPACE class QAction; class QToolBar; class QMainWindow; QT_END_NAMESPACE class CModDocument: public QWidget { Q_OBJECT public: CModDocument(QWidget *parent = 0); QMainWindow *getMainWnd(); public slots: void newFile(); void open(); bool save(); bool saveAs(); private: void createActions(); void createToolBars(); void interCom(); QMainWindow *mainWnd; QToolBar *fileToolBar; QAction *newAct; QAction *openAct; QAction *saveAct; QAction *saveAsAct; }; #endif // CMODDOCUMENT_H </code></pre> <p><a href="http://pastebin.com/3unqywPk" rel="nofollow">CModDocument.cpp</a></p> <pre><code>#include &lt;QtGui&gt; #include &lt;QDebug&gt; #include "CModDocument.h" CModDocument::CModDocument( QWidget *parent ) : QWidget( parent ) , mainWnd( (QMainWindow*)parent ) { createActions(); createToolBars(); interCom(); mainWnd-&gt;statusBar()-&gt;showMessage(tr("Ready")); } void CModDocument::newFile() { qDebug() &lt;&lt; "newFile"; } void CModDocument::open() { qDebug() &lt;&lt; "open"; } bool CModDocument::save() { qDebug() &lt;&lt; "save"; bool retVal; return retVal; } bool CModDocument::saveAs() { qDebug() &lt;&lt; "saveAs"; bool retVal; return retVal; } void CModDocument::createActions() { newAct = new QAction(tr("&amp;New"), this); newAct-&gt;setShortcuts(QKeySequence::New); newAct-&gt;setStatusTip(tr("Create a new file")); openAct = new QAction(tr("&amp;Open..."), this); openAct-&gt;setShortcuts(QKeySequence::Open); openAct-&gt;setStatusTip(tr("Open an existing file")); saveAct = new QAction(tr("&amp;Save"), this); saveAct-&gt;setShortcuts(QKeySequence::Save); saveAct-&gt;setStatusTip(tr("Save the document to disk")); saveAsAct = new QAction(tr("Save &amp;As..."), this); saveAsAct-&gt;setShortcuts(QKeySequence::SaveAs); saveAsAct-&gt;setStatusTip(tr("Save the document under a new name")); } void CModDocument::createToolBars() { fileToolBar = mainWnd-&gt;addToolBar(tr("File")); fileToolBar-&gt;addAction(newAct); fileToolBar-&gt;addAction(openAct); fileToolBar-&gt;addAction(saveAct); } void CModDocument::interCom() { connect(newAct, SIGNAL(triggered()), this, SLOT(newFile())); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); } </code></pre> <p><a href="http://pastebin.com/8pxjvY66" rel="nofollow">CModEditor.h</a></p> <pre><code>#ifndef CMODEDITOR_H #define CMODEDITOR_H #include &lt;QWidget&gt; // #include "CModEdiWidget.h" QT_BEGIN_NAMESPACE class QMainWindow; class QAction; class QMenu; class QMenuBar; class QToolBar; QT_END_NAMESPACE class CModEditor : public QWidget { Q_OBJECT public: CModEditor(QWidget *parent = 0); public slots: void cut(); private: void createActions(); void createToolBars(); void interCom(); QAction *cutAct; QToolBar *editToolBar; // parent QMainWindow *mainWnd; }; #endif </code></pre> <p><a href="http://pastebin.com/0qqVZTMx" rel="nofollow">CModEditor.cpp</a></p> <pre><code>#include &lt;QtGui&gt; #include &lt;QDebug&gt; #include "CModEditor.h" CModEditor::CModEditor(QWidget *parent) : QWidget(parent) , mainWnd( (QMainWindow*)parent ) { createActions(); createToolBars(); interCom(); } void CModEditor::cut() { qDebug() &lt;&lt; "cut"; } void CModEditor::createActions() { cutAct = new QAction(tr("Cu&amp;t"), this); cutAct-&gt;setShortcuts(QKeySequence::Cut); cutAct-&gt;setStatusTip(tr("Cut the current selection's contents to the clipboard")); } void CModEditor::createToolBars() { editToolBar = mainWnd-&gt;addToolBar(tr("Edit")); editToolBar-&gt;addAction(cutAct); editToolBar-&gt;setIconSize(QSize(16, 16)); } void CModEditor::interCom() { connect(cutAct, SIGNAL(triggered()), this, SLOT(cut())); } </code></pre> <p><a href="http://pastebin.com/FsQeFXis" rel="nofollow">build.pro</a></p> <pre><code>CONFIG -= app_bundle HEADERS = CModDocument.h CModEditor.h SOURCES = CModDocument.cpp CModEditor.cpp main.cpp </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload