When you helped me to solve my previous problem, second problem occurred.
Since I am writing this program for learning purposes I am trying to put here as much things as possible :P
This problem is connected to signals and slots
I have class EncryptedBody and class Rsa. In Rsa class I have 4 problematic signals
void encryptbarChange(int value);
void encryptbarMaximum(int value);
void decryptbarChange(int value);
void decryptbarMaximum(int value);
void encryptbarChange(int value);
void encryptbarMaximum(int value);
void decryptbarChange(int value);
void decryptbarMaximum(int value);
To copy to clipboard, switch view to plain text mode
those are emitted in two functions
// String čÃ*slic převede na tring znaků
{
int i = (digitsN - 1); // počet čÃ*slic reprezentujÃ*cÃ* jeden znak - 1
int cNumber = 0;
int cDigit;
int size = textEncrypted.size();
emit decryptbarMaximum(size);
for (int o = 0; o < textEncrypted.size(); o++)
{
QChar cChar_
= textEncrypted.
data()[o
];
// Vezme znak z QString na pozici o a vrátÃ* ho jako QChar char cChar = cChar_.toLatin1(); // Převede QChar na char
cDigit = atoi(&cChar); // Převede char na int
cNumber += cDigit * pow(10, i); // Např. 123 = (1 * 10 ^ 2) + (2 * 10 ^ 1) + (1 * 10 ^ 0) --> tento cyklus spojÃ* čÃ*slice v čÃ*slo
i--;
if (i == -1) // Pokud je i, které sloužÃ* jako exponent rovno -1 čÃ*slo je hotovo a jedem od začátku
{
cNumber = decryption(cNumber);
textNormal.append(cNumber);
i = (digitsN - 1);
cNumber = 0;
}
emit decryptbarChange(o);
}
return textNormal;
}
// String čÃ*slic převede na tring znaků
QString Rsa::toCharacters(QString textEncrypted)
{
QString textNormal;
QTextStream out(&textNormal);
int i = (digitsN - 1); // počet čÃ*slic reprezentujÃ*cÃ* jeden znak - 1
int cNumber = 0;
int cDigit;
int size = textEncrypted.size();
emit decryptbarMaximum(size);
for (int o = 0; o < textEncrypted.size(); o++)
{
QChar cChar_ = textEncrypted.data()[o]; // Vezme znak z QString na pozici o a vrátÃ* ho jako QChar
char cChar = cChar_.toLatin1(); // Převede QChar na char
cDigit = atoi(&cChar); // Převede char na int
cNumber += cDigit * pow(10, i); // Např. 123 = (1 * 10 ^ 2) + (2 * 10 ^ 1) + (1 * 10 ^ 0) --> tento cyklus spojÃ* čÃ*slice v čÃ*slo
i--;
if (i == -1) // Pokud je i, které sloužÃ* jako exponent rovno -1 čÃ*slo je hotovo a jedem od začátku
{
cNumber = decryption(cNumber);
textNormal.append(cNumber);
i = (digitsN - 1);
cNumber = 0;
}
emit decryptbarChange(o);
}
return textNormal;
}
To copy to clipboard, switch view to plain text mode
// String znaků převede na string čÃ*slic (jeden znak je pak pořadÃ* x čÃ*slic, kde x je počet čÃ*slic v N), zachovává bÃ*lé znaky
{
int size = textNormal.size();
emit encryptbarMaximum(size);
for (int i = 0; i < size; i++)
{
QChar cChar
= textNormal.
data()[i
];
ulong cNumber = encryption(cChar.unicode()); // Převede znak na čÃ*slo a zaÅ¡ifruje ho.... encryption(cChar.unicode())
for (uint o = 1; o < digitsN; o++)
{
if (cNumber < pow(10, o))
{
textEncrypted.append('0');
}
}
out << cNumber;
emit encryptbarChange(i);
}
return textEncrypted;
}
// String znaků převede na string čÃ*slic (jeden znak je pak pořadÃ* x čÃ*slic, kde x je počet čÃ*slic v N), zachovává bÃ*lé znaky
QString Rsa::toDigits(QString textNormal)
{
QString textEncrypted;
QTextStream out(&textEncrypted);
int size = textNormal.size();
emit encryptbarMaximum(size);
for (int i = 0; i < size; i++)
{
QChar cChar = textNormal.data()[i];
ulong cNumber = encryption(cChar.unicode()); // Převede znak na čÃ*slo a zaÅ¡ifruje ho.... encryption(cChar.unicode())
for (uint o = 1; o < digitsN; o++)
{
if (cNumber < pow(10, o))
{
textEncrypted.append('0');
}
}
out << cNumber;
emit encryptbarChange(i);
}
return textEncrypted;
}
To copy to clipboard, switch view to plain text mode
I am connecting this signals in EncryptedBody class to two slots
void EncrypterBody::textDecryption()
{
ulong n = keyNumber(key_1->text());
uint d = keyNumber(key_2->text());
/*if (x > y)
{
uint n = x;
uint e = y;
//Rsa encryption = Rsa(false, n, d);
}
else
{
uint n = y;
uint e = x;
//Rsa encryption = Rsa(false, n, d);
}*/
Rsa *decryption = new Rsa(0, false, n, d);
QString textEncrypted
= text
->toPlainText
();
QString textNormal
= decryption
->toCharacters
(textEncrypted
);
QObject::connect(decryption,
SIGNAL(decryptbarMaximum
(int)),
this,
SLOT(setProgressBarMaximum
(int)));
QObject::connect(decryption,
SIGNAL(decryptbarChange
(int)),
this,
SLOT(setProgressBarValue
(int)));
emit clickedTranslate(textNormal);
}
void EncrypterBody::textDecryption()
{
ulong n = keyNumber(key_1->text());
uint d = keyNumber(key_2->text());
/*if (x > y)
{
uint n = x;
uint e = y;
//Rsa encryption = Rsa(false, n, d);
}
else
{
uint n = y;
uint e = x;
//Rsa encryption = Rsa(false, n, d);
}*/
Rsa *decryption = new Rsa(0, false, n, d);
QString textEncrypted = text->toPlainText();
QString textNormal = decryption->toCharacters(textEncrypted);
QObject::connect(decryption, SIGNAL(decryptbarMaximum(int)), this, SLOT(setProgressBarMaximum(int)));
QObject::connect(decryption, SIGNAL(decryptbarChange(int)), this, SLOT(setProgressBarValue(int)));
emit clickedTranslate(textNormal);
}
To copy to clipboard, switch view to plain text mode
void EncrypterBody::textEncryption()
{
ulong n = keyNumber(key_1->text());
uint e = keyNumber(key_2->text());
/*if (x > y)
{
uint n = x;
uint e = y;
//Rsa encryption = Rsa(true, n, e);
}
else
{
uint n = y;
uint e = x;
//Rsa encryption = Rsa(true, n, e);
}*/
Rsa *encryption = new Rsa(0, true, n, e);
QString textNormal
= text
->toPlainText
();
QString textEncrypted
= encryption
->toDigits
(textNormal
);
QObject::connect(encryption,
SIGNAL(encryptbarMaximum
(int)),
this,
SLOT(setProgressBarMaximum
(int)));
QObject::connect(encryption,
SIGNAL(encryptbarChange
(int)),
this,
SLOT(setProgressBarValue
(int)));
emit clickedTranslate(textEncrypted);
}
void EncrypterBody::textEncryption()
{
ulong n = keyNumber(key_1->text());
uint e = keyNumber(key_2->text());
/*if (x > y)
{
uint n = x;
uint e = y;
//Rsa encryption = Rsa(true, n, e);
}
else
{
uint n = y;
uint e = x;
//Rsa encryption = Rsa(true, n, e);
}*/
Rsa *encryption = new Rsa(0, true, n, e);
QString textNormal = text->toPlainText();
QString textEncrypted = encryption->toDigits(textNormal);
QObject::connect(encryption, SIGNAL(encryptbarMaximum(int)), this, SLOT(setProgressBarMaximum(int)));
QObject::connect(encryption, SIGNAL(encryptbarChange(int)), this, SLOT(setProgressBarValue(int)));
emit clickedTranslate(textEncrypted);
}
To copy to clipboard, switch view to plain text mode
and finaly in main.cpp I have this
EncrypterBody *partEncryption = new EncrypterBody(0, true);
EncrypterBody *partDecryption = new EncrypterBody(0, false);
QObject::connect(partEncryption,
SIGNAL(clickedTranslate
(QString)), partDecryption,
SLOT(setText
(QString)));
QObject::connect(partDecryption,
SIGNAL(clickedTranslate
(QString)), partEncryption,
SLOT(setText
(QString)));
EncrypterBody *partEncryption = new EncrypterBody(0, true);
EncrypterBody *partDecryption = new EncrypterBody(0, false);
QObject::connect(partEncryption, SIGNAL(clickedTranslate(QString)), partDecryption, SLOT(setText(QString)));
QObject::connect(partDecryption, SIGNAL(clickedTranslate(QString)), partEncryption, SLOT(setText(QString)));
To copy to clipboard, switch view to plain text mode
I have no problems with calling setText(QString) via clickedTranslate(QString) signal, but I have problems with setting max value a current value of progress bar which is shown, but it does not update when I click Translate button, which should emit clickedTranslated() which calls textEncryption() / textDecryption() in EncryptedBody class and those (textEncryption() /textDecryption()) use functions from Rsa class for encryption decryption and this functions should be emitting decryptbarChange(int), encryptbarChange(int), decryptbarMaximum(int), encryptbarChange(int)
Bookmarks