ich habe was implementiert nun passiert beim ausführen der function ein crash.
also hier mein ChatWindow.cpp
Code: Alles auswählen
#include <QtGui>
#include "rshare.h"
#include "ChatWindow.h"
#include "config/gconfig.h"
#include "QtChatAvatarFrame.h"
#include <QTextCodec>
#include <QTextEdit>
#include <QToolBar>
#include <QTextCursor>
#include <QTextList>
/* Define the format used for displaying the date and time */
#define DATETIME_FMT "MMM dd hh:mm:ss"
#include <sstream>
/** Default constructor */
ChatWindow::ChatWindow(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
/* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this);
GConfig config;
config.loadWidgetInformation(this);
_isAvatarFrameOpened = true;
//creates sub widgets
_avatarFrame = new QtChatAvatarFrame(this);
////
connect(ui.lineEdit, SIGNAL(returnPressed( ) ), this, SLOT(sendChat( ) ));
connect(ui.colorButton, SIGNAL(clicked()), this, SLOT(setColor()));
connect(ui.textboldButton, SIGNAL(clicked()), this, SLOT(textBold()));
connect(ui.textunderlineButton, SIGNAL(clicked()), this, SLOT(textUnderline()));
connect(ui.textitalicButton, SIGNAL(clicked()), this, SLOT(textItalic()));
connect(ui.avatarFrameButton, SIGNAL(clicked()), SLOT(avatarFrameButtonClicked()));
addAvatarFrame();
}
/**
Overloads the default show() slot so we can set opacity*/
void
ChatWindow::show()
{
//loadSettings();
if(!this->isVisible()) {
QMainWindow::show();
}
}
void ChatWindow::closeEvent (QCloseEvent * event)
{
QMainWindow::closeEvent(event);
}
void ChatWindow::setColor()
{
QColor col = QColorDialog::getColor(Qt::green, this);
if (col.isValid()) {
ui.colorButton->setPalette(QPalette(col));
QTextCharFormat fmt;
fmt.setForeground(col);
mergeFormatOnWordOrSelection(fmt);
colorChanged(col);
}
}
void ChatWindow::textBold()
{
QTextCharFormat fmt;
fmt.setFontWeight(ui.textboldButton->isChecked() ? QFont::Bold : QFont::Normal);
mergeFormatOnWordOrSelection(fmt);
}
void ChatWindow::textUnderline()
{
QTextCharFormat fmt;
fmt.setFontUnderline(ui.textunderlineButton->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void ChatWindow::textItalic()
{
QTextCharFormat fmt;
fmt.setFontItalic(ui.textitalicButton->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void ChatWindow::currentCharFormatChanged(const QTextCharFormat &format)
{
fontChanged(format.font());
colorChanged(format.foreground().color());
}
void ChatWindow::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
QTextCursor cursor = ui.textBrowser->textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
ui.textBrowser->mergeCurrentCharFormat(format);
}
void ChatWindow::fontChanged(const QFont &f)
{
//comboFont->setCurrentIndex(comboFont->findText(QFontInfo(f).family()));
//comboSize->setCurrentIndex(comboSize->findText(QString::number(f.pointSize())));
ui.textboldButton->setChecked(f.bold());
ui.textunderlineButton->setChecked(f.italic());
ui.textitalicButton->setChecked(f.underline());
}
void ChatWindow::colorChanged(const QColor &c)
{
QPixmap pix(16, 16);
pix.fill(c);
ui.colorButton->setIcon(pix);
}
void ChatWindow::updateChat()
{
/* get chat off queue */
/* write it out */
}
void ChatWindow::addChatMsg()
{
}
void ChatWindow::sendChat()
{
}
void ChatWindow::avatarFrameButtonClicked() {
if (_isAvatarFrameOpened) {
removeAvatarFrame();
} else {
addAvatarFrame();
}
}
void ChatWindow::addAvatarFrame() {
QBoxLayout * glayout = dynamic_cast<QBoxLayout *>(layout());
_avatarFrame->setVisible(true);
//_avatarFrame->setMinimumSize(64, 0);
glayout->insertWidget(1, _avatarFrame);
_isAvatarFrameOpened = true;
ui.avatarFrameButton->setIcon(QIcon(":images/show_toolbox_frame.png"));
update();
}
void ChatWindow::removeAvatarFrame() {
QBoxLayout * glayout = dynamic_cast<QBoxLayout *>(layout());
_avatarFrame->setVisible(false);
_avatarFrame->setMinimumSize(0, 0);
glayout->removeWidget(_avatarFrame);
_isAvatarFrameOpened = false;
ui.avatarFrameButton->setIcon(QIcon(":images/hide_toolbox_frame.png"));
update();
}
void ChatWindow::updateUserAvatar() {
QPixmap pixmap;
//std::string myData = _cChatHandler.getCUserProfile().getUserProfile().getIcon().getData();
//pixmap.loadFromData((uchar *)myData.c_str(), myData.size());
_avatarFrame->setUserPixmap(pixmap);
}Code: Alles auswählen
#ifndef _CHATWINDOW_H
#define _CHATWINDOW_H
#include "ui_ChatWindow.h"
#include "rsiface/rsiface.h"
#include <QDialog>
class QtChatAvatarFrame;
class QAction;
class QTextEdit;
class QTextCharFormat;
class ChatWindow : public QMainWindow
{
Q_OBJECT
public:
/** Default constructor */
ChatWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default destructor */
void updateChat();
void addChatMsg();
public slots:
/** Overloaded QWidget.show */
void show();
protected:
void closeEvent (QCloseEvent * event);
private slots:
void setColor();
void textBold();
void textUnderline();
void textItalic();
void sendChat();
void currentCharFormatChanged(const QTextCharFormat &format);
void avatarFrameButtonClicked();
private:
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
void fontChanged(const QFont &f);
void colorChanged(const QColor &c);
void addAvatarFrame();
void removeAvatarFrame();
//void updateAvatarFrame();
void updateUserAvatar();
bool _isAvatarFrameOpened;
QtChatAvatarFrame * _avatarFrame;
QAction *actionTextBold;
QAction *actionTextUnderline;
QAction *actionTextItalic;
//std::string dialogId, dialogName;
//unsigned int lastChatTime;
//std::string lastChatName;
/** Qt Designer generated object */
Ui::ChatWindow ui;
};
#endif
habs nicht umbenant von einer anderen klasse...
beim compilieren kommt kein einziger fehler...
aber beim ausführen von:
Code: Alles auswählen
void MessagesDialog::eventsButtonClicked()
{
ChatWindow * chatwin = new ChatWindow();
chatwin->show();
}