PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : GTK Anwendung beenden



Suffkopf
18-11-2004, 15:38
wenn z.B. id nicht 0 ist dann soll die GTK Anwendung beendet werden aber so wie ich es gemacht hat klappt es nicht.

if (id!=0)
{
gtk_main_quit ();
}

Als Fehlermeldung kommt das:

(process:2620): Gtk-CRITICAL **: file gtkmain.c: line 1231 (gtk_main_quit): assertion `main_loops != NULL' failed

aber kompilieren geht einwandfrei.

Matflasch
18-11-2004, 16:33
kann sein, dass da nen denkfehler drin is?

Kannst den Quelltext mal posten?

Mfg, Matflasch

Suffkopf
18-11-2004, 18:28
Bei int main() steht es gleich hinter den Variablen.


#include <gtk/gtk.h>
#include <iostream>
#include <string>
#include <sstream>
#include <unistd.h>

using namespace std;

void connect (GtkWidget *widget,
GtkWidget *text)

{
string device1;
const gchar *entry_text;
entry_text = gtk_entry_get_text (GTK_ENTRY (text));
device1 = entry_text;
system("/etc/init.d/isdnutils start ");
system(("/usr/sbin/isdnctrl dial " + device1).c_str());
}

void disconnect( GtkWidget *widget,
GtkWidget *text)
{
string device2;
const gchar *entry_text;
entry_text = gtk_entry_get_text (GTK_ENTRY (text));
device2 = entry_text;
system(("/usr/sbin/isdnctrl hangup " + device2).c_str());
system("/etc/init.d/isdnutils stop");
}


static void quit( GtkWidget *widget,
GdkEvent *event,
gpointer data )
{
gtk_main_quit ();
}

int main( int argc, char *argv[] )
{


GtkWidget *window;
GtkWidget *button1;
GtkWidget *button2;
GtkWidget *button3;
GtkWidget *text;
GtkWidget *table;

int id;
id = getuid();
if (id!=0)
{
printf("You must be root!");
gtk_main_quit();
}


gtk_init (&argc, &argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

gtk_window_set_title (GTK_WINDOW (window) , "Dial-0.1-alpha");

gtk_container_set_border_width (GTK_CONTAINER (window), 25);

table = gtk_table_new (4, 0, TRUE);
gtk_container_add (GTK_CONTAINER (window), table);

text = gtk_entry_new();
gtk_entry_set_max_length (GTK_ENTRY (text), 15);
gtk_entry_set_text (GTK_ENTRY (text), "ippp0");


button1 = gtk_button_new_with_label ("connect");
button2 = gtk_button_new_with_label ("disconnect");
button3 = gtk_button_new_with_label ("exit");

gtk_table_attach_defaults (GTK_TABLE (table), button1, 0, 1, 0, 1);
gtk_widget_show(button1);
gtk_table_attach_defaults (GTK_TABLE (table), button2, 0, 1, 1, 2);
gtk_widget_show(button2);
gtk_table_attach_defaults (GTK_TABLE (table), button3, 0, 1, 2, 3);
gtk_widget_show(button3);
gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 3, 4);
gtk_widget_show(text);


g_signal_connect (G_OBJECT (button1), "clicked",
G_CALLBACK (connect),
(gpointer) text);
g_signal_connect (G_OBJECT (button2), "clicked",
G_CALLBACK (disconnect),
(gpointer) text);
g_signal_connect (G_OBJECT (button3), "clicked",
G_CALLBACK (quit), NULL);

g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (quit), NULL);


gtk_widget_show (table);
gtk_widget_show (window);
gtk_main ();
return 0;
}

anda_skoa
18-11-2004, 18:38
(process:2620): Gtk-CRITICAL **: file gtkmain.c: line 1231 (gtk_main_quit): assertion `main_loops != NULL' failed


Du rufst gtk_main_quit zu einem Zeitpunkt auf, wo GTK noch gar nicht initialisiert ist, gescheige denn läuft.

Einfach exit(EXIT_FAILURE) benutzen.

Ciao,
_

Suffkopf
18-11-2004, 19:09
Aha jetzt funzt :D
Danke

Ich muss allerdings nochmal nerven, und zwa wie bekomme ich diese char Variable dazu das sie in gtk_entry_set_text verwenden kann. Da gehen doch nur const gchar rein oder wie ? Auf jeden Fall soll hier das bla im entry stehen:

char bla[20]
FILE* number=popen("egrep LOCALMSN /etc/isdn/device.ippp0 | awk '{ print $1 } ' | cut -b 10-20","r");

peschmae
18-11-2004, 19:37
Bitte ein andermal [ code ] tags [ / code ] (der #-Button in der "Toolbar") drumtun :)

MfG Peschmä