ich glaub zwar das einige genervt sind von der Frage die ich hier stelle aber ich versuch es doch einmal
Ich versuche unter Windows mit dem Microsoft VC 2005 Studio eine Aplikation zu erstellen. Ich hoffe das ich die Qt4 Bibliotheken richtig eingebunden zu haben, jedenfalls läßt es sich compelieren und starten. Mein Problem ist jetzt das ich ein Menü erstellen möchte (oder habe) und wenn der Anwender auf ein Menüunterpunkt clicked möcht ich das eine Procedur aufgerufen wird. Das Problem ist nur das ich in der Console immer den Hinweiß bekomme das die slots nicht bekannt sind.
Vielleicht kann mir ja jemand einen Tip geben wo der Fehler ist.
Mein main Teil:
#include "stdafx.h"
#include <QApplication>
#include <QPushButton>
#include <QTreeView>
#include <QListWidget>
#include <QHeaderView>
#include <QStandardItemModel>
#include <QtGui>
#include "RandCPmp3.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
int width = 800, hight = 600;
CRandCPmp3 RandCPmp3 (NULL, "RandCPmp3", width, hight);
RandCPmp3.Go ();
RandCPmp3.show();
return app.exec();
}
Mein *.h Teil:
#ifndef RANDCPMP3_H
#define RANDCPMP3_H
#define _FILE_MENU "File"
#define _OPTION_MENU "Option"
#include <QApplication>
#include <QWidget>
#include <QTreeView>
class CRandCPmp3 : public QWidget
{
// Q_OBJECT
public:
CRandCPmp3();
CRandCPmp3(QWidget *parent = 0, const char *name = 0, int width = 800, int hight=600);
/* ~CRandCPmp3()
{}
*/
void Go ();
private:
QMenu *test;
QAction *testAct;
protected:
void Resize ();
char* itoa (int a, char *str, int base);
char* itoa (long a, char *str, int base);
char* itoa (unsigned long a, char *str, int base);
public slots:
void slotEnd ();
void slotGetExistDirMp3 ();
void slotGetCreateDirMp3 ();
void slotSelectRandomMp3 ();
void slotTest (int);
signals:
void call ();
};
#endif // RANDCPMP3_H
Und mein *.cpp Teil:
#include "stdafx.h"
#include "RandCPmp3.h"
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <QApplication>
#include <QWidget>
#include <QTreeView>
#include <QListWidget>
#include <QHeaderView>
#include <QStandardItemModel>
#include <QtGui>
/*
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
*/
CRandCPmp3::CRandCPmp3(QWidget *parent, const char *name, int width, int hight)
: QWidget(parent)
{
QMenuBar *menuBar;
menuBar = new QMenuBar (this);
QMenu *file, *option;
file = new QMenu (_FILE_MENU, this);
option = new QMenu (_OPTION_MENU, this);
test = new QMenu ("test", this);
menuBar->addMenu (file);
menuBar->addMenu (option);
menuBar->addMenu (test);
testAct = new QAction("&Get directory with contained mp3 files", (QObject*) menuBar);
testAct->setShortcut(tr("Ctrl+G"));
testAct->setStatusTip(tr("Open an existing file"));
connect(testAct, SIGNAL(triggered()), this, SLOT(slotTest(1)));
test->addAction(testAct);
test->addSeparator ();
//add item for first menu
QAction *openAct;
openAct = new QAction("&Get directory with contained mp3 files", (QObject*) this);
openAct->setShortcut(tr("Ctrl+G"));
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(slotGetExistDirMp3()));
file->addAction(openAct);
file->addSeparator ();
//add item for first menu
openAct = new QAction("S&elect (or create) directory to save the selected mp3 files", (QObject*) this);
openAct->setShortcut(tr("Ctrl+S"));
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(slotGetCreateDirMp3()));
file->addAction(openAct);
file->addSeparator ();
//add item for first menu
openAct = new QAction(tr("&Exit"), (QObject*) this);
openAct->setShortcut(tr("Ctrl+E"));
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(slotEnd()));
file->addAction(openAct);
file->addSeparator ();
//add item for second menu
openAct = new QAction("Select &random MP3(s)", (QObject*) this);
openAct->setShortcut(tr("Ctrl+R"));
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(slotSelectRandomMp3()));
option->addAction(openAct);
option->addSeparator ();
QTreeView *sourceView;
sourceView = new QTreeView (this);
sourceView->setRootIsDecorated(false);
sourceView->setAlternatingRowColors(true);
QStringList longerList = (QStringList() << "Number" << "File" << "Space");
QStandardItemModel *model = new QStandardItemModel (3,2,this);
model->setHorizontalHeaderLabels (longerList);
sourceView->setModel(model);
sourceView->show();
sourceView->move ( 200, 300 );
resize(width, hight);
}
CRandCPmp3::CRandCPmp3()
/* : QWidget(parent)*/
{
}
char* CRandCPmp3::itoa (int a, char *str, int base)
{
// strcpy (str, "%a");
char tmp [15] = "";
//clear the string
memset (tmp, 0, sizeof(tmp));
switch (base)
{ case 16:
sprintf (tmp, "%x", a);
break;
case 8:
sprintf (tmp, "%o", a);
break;
default :
sprintf (tmp, "%i", a);
break;
}
strcpy (str, tmp);
return str;
}
char* CRandCPmp3::itoa (long a, char *str, int base)
{
// strcpy (str, "%a");
char tmp [25] = "";
//clear the string
memset (tmp, 0, sizeof(tmp));
switch (base)
{ case 16:
sprintf (tmp, "%x", a);
break;
case 8:
sprintf (tmp, "%o", a);
break;
default :
sprintf (tmp, "%d", a);
break;
}
strcpy (str, tmp);
return str;
}
char* CRandCPmp3::itoa (unsigned long a, char *str, int base)
{
// strcpy (str, "%a");
char tmp [25] = "";
//clear the string
memset (tmp, 0, sizeof(tmp));
switch (base)
{ case 16:
sprintf (tmp, "%x", a);
break;
case 8:
sprintf (tmp, "%o", a);
break;
default :
sprintf (tmp, "%d", a);
break;
}
strcpy (str, tmp);
return str;
}
void CRandCPmp3::Go ()
{int a;
a = 1;
}
void CRandCPmp3::Resize ()
{
}
void CRandCPmp3::slotEnd ()
{
qDebug("slotEnd () is called");
}
void CRandCPmp3::slotGetExistDirMp3 ()
{
qDebug("slotGetExistDirMp3 () is called");
}
void CRandCPmp3::slotGetCreateDirMp3 ()
{
qDebug("slotGetCreateDirMp3 () is called");
}
void CRandCPmp3::slotSelectRandomMp3 ()
{
qDebug("slotEnd () is called");
}
void CRandCPmp3::slotTest (int a)
{
qDebug("slotTest () is called");
}
void CRandCPmp3::call ()
{
qDebug("call () is called");
}
Über Hinweise wäre ich sehr dankbar.
gruß