Flayer
13th January 2010, 13:57
Hello, and sorry for being such a newb by asking, which I believe really is a simple thing.
Okay, here's the thing.
I want to do a simple editor, which then will check the input characters and change them to something else, and the
set them in the QTextEdit.
What I mean is that, when I write for eg. a 2, it will be checked against a list of characters, and if there's a match, change the 2 into
a specific text/chars.
I want it to change my 2 to a G#. But the QTextEdit shouldn't input characters that I don't want, eg. z, x etc.
And as you may already know, I am newb, just started with Qt yesterday :P
Im not a complete newb when it comes to C++, even tho it may seem so. I just have a hard time figuring out what needs to be done
and how to do it "right".
I've been looking through this forum, the Qt docs and google, but without success.
So, even if it's against my principles, I decided to ask you guys here at the forum.
When I execute my program, it gives me the SIGSEV signal when I try to edit the text in my QTextEdit.
The code looks like this atm:
dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QLineEdit>
#include <QLabel>
#include <QTextEdit>
class myDialog : public QDialog
{
Q_OBJECT
private:
QLineEdit* m_lneTitle;
QLabel* m_lTitle;
QTextEdit* m_document;
private slots:
void textEditSlot();
public:
myDialog();
virtual ~myDialog(){};
};
#endif // DIALOG_H
dialog.cpp
#include "dialog.h"
myDialog::myDialog()
{
//fönsterstorlek samt pos. vart den ska vara när app. startas
this->setGeometry(200, 100, 600, 400);
//skapa en label
m_lTitle = new QLabel(this);
m_lTitle->setText("Song Title:");
m_lTitle->setGeometry(20, 20, 80, 20);
// skapa lineedit, till songtiteln
m_lneTitle = new QLineEdit(this);
m_lneTitle->setGeometry(80, 20, 140, 20);
//skapa själva editrutan
m_document = new QTextEdit(this);
m_document->setGeometry(20, 60, 560, 300);
//koppla lite signaler
connect(m_document, SIGNAL(textChanged()), this, SLOT(textEditSlot()));
}
void myDialog::textEditSlot()
{
// haven't put anything here atm, cuz anything in here makes it crasch. with anything I mean like m_document->setText();
}
main.cpp
#include <QApplication>
#include "dialog.h"
int main(int argc, char **argv)
{
QApplication app( argc, argv );
myDialog* d = new myDialog();
d->show();
return app.exec();
}
I haven't put any code in the signal slot right now, cuz everything that I tried just crashed the program.
Is this because of the "SIGNAL(textChanged()"?
If so, what should I use instead?
Oh, and I could be satisfied with any solution, I just want to get this to work right now.
If it's possible to catch the keyboard event, which I assume is, how would I do that and then set the text in the QTextEdit via
that function?
The reason I want this to work is because I feel that me and my buddy, who happens to be a way better coder than me, created
an application in SDL which reads "notes" from a text file, and then output the sound via either the PC-speaker or via the speakers.
Now you may think: "Well, if your buddy is such a better coder than you, why doesn't he create this?".
Well, the answer to that is: "Because I want to learn more, I want to "grow"."
So, please. If you feel like helping me out here, it would be greatly appreciated.
/Flayer
Okay, here's the thing.
I want to do a simple editor, which then will check the input characters and change them to something else, and the
set them in the QTextEdit.
What I mean is that, when I write for eg. a 2, it will be checked against a list of characters, and if there's a match, change the 2 into
a specific text/chars.
I want it to change my 2 to a G#. But the QTextEdit shouldn't input characters that I don't want, eg. z, x etc.
And as you may already know, I am newb, just started with Qt yesterday :P
Im not a complete newb when it comes to C++, even tho it may seem so. I just have a hard time figuring out what needs to be done
and how to do it "right".
I've been looking through this forum, the Qt docs and google, but without success.
So, even if it's against my principles, I decided to ask you guys here at the forum.
When I execute my program, it gives me the SIGSEV signal when I try to edit the text in my QTextEdit.
The code looks like this atm:
dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QLineEdit>
#include <QLabel>
#include <QTextEdit>
class myDialog : public QDialog
{
Q_OBJECT
private:
QLineEdit* m_lneTitle;
QLabel* m_lTitle;
QTextEdit* m_document;
private slots:
void textEditSlot();
public:
myDialog();
virtual ~myDialog(){};
};
#endif // DIALOG_H
dialog.cpp
#include "dialog.h"
myDialog::myDialog()
{
//fönsterstorlek samt pos. vart den ska vara när app. startas
this->setGeometry(200, 100, 600, 400);
//skapa en label
m_lTitle = new QLabel(this);
m_lTitle->setText("Song Title:");
m_lTitle->setGeometry(20, 20, 80, 20);
// skapa lineedit, till songtiteln
m_lneTitle = new QLineEdit(this);
m_lneTitle->setGeometry(80, 20, 140, 20);
//skapa själva editrutan
m_document = new QTextEdit(this);
m_document->setGeometry(20, 60, 560, 300);
//koppla lite signaler
connect(m_document, SIGNAL(textChanged()), this, SLOT(textEditSlot()));
}
void myDialog::textEditSlot()
{
// haven't put anything here atm, cuz anything in here makes it crasch. with anything I mean like m_document->setText();
}
main.cpp
#include <QApplication>
#include "dialog.h"
int main(int argc, char **argv)
{
QApplication app( argc, argv );
myDialog* d = new myDialog();
d->show();
return app.exec();
}
I haven't put any code in the signal slot right now, cuz everything that I tried just crashed the program.
Is this because of the "SIGNAL(textChanged()"?
If so, what should I use instead?
Oh, and I could be satisfied with any solution, I just want to get this to work right now.
If it's possible to catch the keyboard event, which I assume is, how would I do that and then set the text in the QTextEdit via
that function?
The reason I want this to work is because I feel that me and my buddy, who happens to be a way better coder than me, created
an application in SDL which reads "notes" from a text file, and then output the sound via either the PC-speaker or via the speakers.
Now you may think: "Well, if your buddy is such a better coder than you, why doesn't he create this?".
Well, the answer to that is: "Because I want to learn more, I want to "grow"."
So, please. If you feel like helping me out here, it would be greatly appreciated.
/Flayer