有这样的事情吗?我一直在查看 Vala API 并且 Regex 对象似乎不支持捕获组,以便我以后可以引用它们。目前有没有办法绕过这个明显的限制?假设我正在从一组字符串(文件的内容)中解析一个字符串,以获得给定的模式,例如:
参数 = 值
但我希望语法宽松,这样它也可以说
参数=值或者
参数 = 值等等...我想到的第一个想法是使用带有捕获组的正则表达式,但据我所知,目前似乎不支持将此功能作为 Vala 的一部分。
我能想出的唯一替代方法是使用匹配空格的正则表达式拆分字符串,以便我最终得到一个可以分析的数组,但该文件可能不仅包含类似“参数 = 值”的格式行。
我是Vala的新手,但是当我尝试修改函数中的参数变量时,我似乎遇到了一个奇怪的问题.例如,这不起作用:
public string changeString(string input) {
input = input.down();
return input;
}
Run Code Online (Sandbox Code Playgroud)
(我得到这个错误:) Invalid assignment from owned expression to unowned variable: input = input.down();
但这确实有效:
public string changeString(string input) {
string temp = input;
temp = temp.down();
return temp;
}
Run Code Online (Sandbox Code Playgroud)
我是否正确认为参数变量无法在Vala中修改?如果是这样,为什么?还有比上面更好的解决方法吗?
我正在使用Vala和GTK +,现在我正在尝试将自定义CSS添加到指定的小部件.我可以添加fe.backgroudn到GtkWidget但不适用于#sidebar
#sidebar { //It doesn't work
color: white;
}
GtkWindow { // It works
background-color: red;
}
Run Code Online (Sandbox Code Playgroud)
我正在为这个小部件添加类:
sidebar = new Gtk.Label("Hello");
sidebar.set_name("sidebar");
Run Code Online (Sandbox Code Playgroud)
它改变了GtkWindow的颜色,但不是这个标签.
有任何想法吗?
下面是我正在玩的Vala程序的一些代码.它在Ubuntu 12.04 ATI机器上运行良好,但是当我切换到运行相同操作系统的Nvidia(8400M GS)机器时,我得到零fbConfigs并且从glXChooseFBConfig返回null.
为什么会发生这种情况?这是获取FB配置和VisualInfo以使用GLX创建OpenGL上下文的最佳方式,还是我应该采用不同的方式?
int errorBase;
int eventBase;
int[] glAttrs;
int[] attrs;
FBConfig* fbConfig;
x_server = xServer;
if (screen == int.MIN)
{
screen = x_server.default_screen().screen_number_of_screen();
}
message("Creating Linux context.");
if (glXQueryExtension(x_server, out errorBase, out eventBase) == false)
{
error("GLX extension is not supported.");
}
if (x_server.render_query_extension(out errorBase, out eventBase) ==
false)
{
error("X11 Render extension is not available.");
}
// Get the visual information for this window
// so OpenGL has what it needs.
glAttrs = new int[0]; …Run Code Online (Sandbox Code Playgroud) 所以我有一个列表框:
var listbox = new Gtk.ListBox();
var l = new Watcher.ListItem.NewItem("title","subtitle", "etc");
listbox.insert(l, 0);
Run Code Online (Sandbox Code Playgroud)
"l"基本上是带有格式化标签和东西的Gtk.ListBoxRow.
我添加了一个标签为"New"的按钮,其目的是将新项添加到ListBox中.
int i = 1;
back_new.clicked.connect( ()=>{
l = new Watcher.ListItem.NewItem("title2", "subtitle2", "etc2");
listbox.insert(l, i);
i++;
});
Run Code Online (Sandbox Code Playgroud)
问题是,如果我检查" listbox.get_row_at_index(2) "它表明列表框中有东西,所以发生了一些事情,但gui中的列表框没有更新.
如果需要,可以在此处获取完整代码:http: //pastebin.com/u/Levike
当我使用此页面中的任何代码而不修改任何内容时:https://wiki.gnome.org/Projects/Vala/AsyncSamples
\n\n我总是得到:\nwarning: \xe2\x80\x98g_simple_async_result_new\xe2\x80\x99 is deprecated: Use \'g_task_new\' instead.
所以我继续建议使用GTask。然而,当我尝试在 Vala 中使用 GLib.Task 时,我在声明任务时陷入困境。因此,我没有在自己的代码中使用 GIO 的异步(因为它已被弃用),而是尝试使用 GLib.Task 来简单地使用 for 循环中的数字更新 Gtk 按钮的标签,这样代码如下所示:
\n\nusing Gtk;\nButton button;\n\npublic static int main (string[] args) {\n Gtk.init (ref args);\n\n var window = new Window ();\n window.title = "Count without blocking the UI";\n window.border_width = 10;\n window.window_position = WindowPosition.CENTER;\n window.set_default_size (350, 70);\n window.destroy.connect (Gtk.main_quit);\n button = new Button.with_label ("Start counting");\n button.clicked.connect (() => {\n GLib.Task task = new GLib.Task(button, new …Run Code Online (Sandbox Code Playgroud) 我知道可以使用以下简单语法按名称设置基于 GLib.Object 的类的属性
obj["foo"] = bar;
Run Code Online (Sandbox Code Playgroud)
有没有办法以类似的方式获得财产的价值?以下构建似乎不起作用:
Bar bar = obj["foo"];
Run Code Online (Sandbox Code Playgroud)
Vala 返回错误:不允许调用 void 方法作为表达式
我知道可以按照下面的示例来完成,但我正在寻找更简洁的东西。
Bar bar;
obj.get("foo", out bar);
Run Code Online (Sandbox Code Playgroud) 如何使用vala(gtk)从某个站点(例如www.google.com)获取HTML代码?我正在使用Val(a)IDE进行编程.
如果有人需要,这是我的代码:
public class Main
{
public static int main (string[] args)
{
Gtk.init (ref args);
Gtk.Window window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
window.title = "First test app";
window.set_default_size (320, 420);
window.position = Gtk.WindowPosition.CENTER;
window.destroy.connect(Gtk.main_quit);
var buttonBack = new Gtk.Button.with_label ("<");
var buttonForward = new Gtk.Button.with_label (">");
var buttonRefresh = new Gtk.Button.with_label ("Refresh");
var buttonStop = new Gtk.Button.with_label ("Stop");
buttonBack.set_size_request (20, 40);
buttonForward.set_size_request (20, 40);
buttonRefresh.set_size_request (20, 40);
buttonStop.set_size_request (20, 40);
//window.add (buttonBack);
var label1 = new Gtk.Label ("There will be …Run Code Online (Sandbox Code Playgroud) 这些关键字应该如何以及何时使用?
它们与C#的目的是否相同?
我正在尝试使用Vala和GTK构建我的第一个基于webkit的应用程序.我对这些语言以及编译它们的过程都很陌生,所以任何帮助都会很棒.
这是我收到的错误:
/home/elementary/GTKProjects/Fookbase/src/fookbase_main.vala:2.7-2.12:错误:使用WebKit找不到命名空间名称"WebKit";
/home/elementary/GTKProjects/Fookbase/src/fookbase_main.vala:13.13-13.19:错误:无法找到类型名称"WebView"私有WebView web_view;
这是我的代码:
using Gtk;
using WebKit;
public class Fookbase : Window {
private const string TITLE = "Fookbase";
private const string HOME_URL = "http://fookbase.com";
private const string DEFAULT_PROTOCOL = "http";
private Regex protocol_regex;
private Entry url_bar;
private WebView web_view;
private Label status_bar;
private ToolButton back_button;
private ToolButton forward_button;
private ToolButton reload_button;
public Fookbase () {
this.title = Fookbase.TITLE;
set_default_size (500, 800);
try {
this.protocol_regex = new Regex (".*://.*");
} catch (RegexError e) {
critical ("%s", e.message); …Run Code Online (Sandbox Code Playgroud)