Programmieren – die besten Beiträge

Mein C++ Qt creator Programm stürzt bei eingaben von umlauten in ein Textfeld ab wie kann ich das verhindern?

Hallo in meinem Programm soll man wenn man einen text eingibt bestimmte dinge analysieren können(Zahl der Buchstaben, Zahl der Vokal ,...) ? allerdings stürzt das Programm ab, sobald man Umlaute eingibt

Mein bisheriger code aus mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->pushButton->hide();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btnBuchstaben_clicked()
{
    DeleteLetter();
    CountLetter();
    ShowLetter();

}

void MainWindow::DeleteLetter()
{
    for (int i=0;i<256;i++)
        Buchstaben[i]=0;
}

void MainWindow::ShowLetter()
{
    QString work="";
    QString einzel;
    QString zahl;
    ui->AnalyseWidget->clear();
    ui->AnalyseWidget->addItem("Auswertung");
    for (int i=0;i<256;i++){
        einzel ="  _____ ";
        if (i>=32)
            einzel[0]=char(i);
        else {
            if (i<10){
                einzel[0]='0';
                einzel[1]='0'+i;
            }
            else if (i< 20) {
                einzel[0]='1';
                einzel[1]='0'+i-10;
            }
            else if (i<30) {
                einzel[0]='2';
                einzel[1]='0'+i-20;

            }
            else {
                einzel[0]='3';
                einzel[1]='0'+i-30;
            }
        }
        zahl = QString::number(Buchstaben[i]);
        for (int j = zahl.length()-1;j>=0;j--)
            einzel[7-zahl.length()+j]=zahl[j];
        work = work + einzel;
        if ((i+1)%8==0)
        {
            ui->AnalyseWidget->addItem(work);
            work="";
        }
    }

}

void MainWindow::CountLetter()
{
    QString Area = ui -> EingabeEdit -> toPlainText();
    for(int i = 0; i < Area.length();i++)
        Buchstaben[Area[i].toLatin1()]++;
}

void MainWindow::on_btnWoerter_clicked()
{
    CountWords();
}

void MainWindow::CountWords()
{
    QString Area;
    Area = ui -> EingabeEdit -> toPlainText();
    int i = 0, w = 0;
    bool Word = false;
    while (i < Area.length())
    {
        if (Area[i] == ' ' && Word)
        {
            Word = false;
            w++;
        }
        if (Area[i] == ' ' && !Word)
        {

        }
        if (Area[i] != ' ' && Word)
        {

        }
        if (Area[i] != ' ' && !Word)
        {
            Word = true;
        }
        i++;
    }
    if (Word == true)
    {
        w++;
    }
    QString o = QString::number(w);
    QString output = "Der Text hat " + o + " Wörter";
    ui -> AnalyseWidget -> clear();
    ui -> AnalyseWidget -> addItem(output);

}

//Vokale - aus vorhandenem Array rausholen
//Zahlen nachschauen und ausgeben



Computer, Technik, programmieren, Cplusplus, Qt Creator

Wie kann ich meinen Python-Code schneller machen?

Hallo,

ich habe gestern in Python ein paar Funktionen geschrieben, die mir ein interessantes Bild ausrechnen sollen. Ich kriege es jedoch nicht hin, dass das Programm einigermaßen schnell läuft und am Ende muss auch die Auflösung darunter leiden

Wenn da mal jemand drüberschauen könnte, wäre das wirklich hilfreich.

import numpy as np
import matplotlib.pyplot as plt
from math import pi, sqrt, atan

#Punkt definieren
class point:
    def __init__(self,x=0,y=0,z=0):
        self.x = x
        self.y = y

    #Operationen
    def __str__(self):
        return "({0},{1})".format(self.x, self.y)

    def __add__(self, other):
        return point(self.x+other.x,self.y+other.y)

    def __sub__(self, other):
        return point(self.x - other.x, self.y - other.y)

    def __abs__(self):
        return sqrt(self.x**2 + self.y**2)

    def __mul__(self, other):
        if type(other) == point:
            return point(self.x * other.x, self.y * other.y)
        return point(self.x * other, self.y * other)

    def __truediv__(self, other):
        if type(other) == point:
            return point(self.x / other.x, self.y / other.y)
        return point(self.x / other, self.y / other)

    def __neg__(self):
        return point(-self.x,-self.y)

# weitere Funktionen für Punkte
def dis(PointA,PointB):
    return abs(PointB-PointA)

def dir(PointA,PointB):
    return (PointB-PointA)/dis(PointA,PointB)


#Funktion für den Wert
def grav_v(x,y,time=5,frames=60):
    p = point(-1,0)
    sp = point(x+1,y)

    c = point(0,0)
    sc = point(0,0)
    
    #Vielleicht wegen des for-loops so langsam?
    for k in range(frames*time):
        try:
            plus = dir(p,c) * 1/dis(p,c)**2 / frames
            sp += plus
            p += sp/frames
            sc -= plus
            c += sc/frames
        except:
            pass

    return p


#Funktion für das Bild
def grav_c(a=-4, b=4, smoothness=1):
    ROWS = []
    p = 0
    print(0)
    #zwei for-loops...
    for Y in np.linspace(a,b,int(200*smoothness)):
        row = []
        for X in np.linspace(a,b,int(200*smoothness)):
            g = grav_v(X, Y)
            row.append( (abs(atan(g.x)*2/pi), abs(atan(g.y)*2/pi), abs(atan(abs(g))*2/pi)) )
        ROWS.append(row)
        p += 1
        print(p / (200 * smoothness))
    plt.imshow(ROWS, extent=(a, b, a, b))
    plt.show()

grav_c()
Computer, Programm, programmieren, Effizienz, Informatik, Programmiersprache, Python

Meistgelesene Beiträge zum Thema Programmieren